using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
using MEA.AE_BusinessLogic.Properties;
using MEA.AE_Data;
using MEA.AE_Data.Access;
using MEA.AE_Data.Config;
using MEA.Misc;

namespace MEA.AE_BusinessLogic
{
	public class ServiceLayer
	{
		public delegate void LiveViewConfigDataLoadedHandler(List<string> sigDescA, List<string> sigDescB, bool AuxEnable, string AuxAdr, int AuxLength, bool expertEnabled, int recordInterval_ms);

		public delegate ConfigSecurity.e_USBDongleTypes SecurityDongleCodeHandler(object sender, ServiceLayerBoolEventArg e);

		private enum EGrapphObjType
		{
			eNoGraphObjType,
			eEventRecGraphType,
			eDataLogGraphType,
			eLiveViewGraphType
		}

		private class GaphObj
		{
			public EGrapphObjType grphType;

			public string logPath;

			public object uiGraph;

			public object recManA;

			public object recManB;

			public GaphObj(EGrapphObjType type)
			{
				grphType = type;
			}
		}

		public struct LiveViewStruct
		{
			public DateTime recordStartTime;

			public int recordIntervalA_ms;

			public int recordIntervalB_ms;

			public List<List<float>> samplesA;

			public List<List<float>> samplesB;
		}

		private BaseService baseServiceA;

		private BaseService baseServiceB;

		private ECU_Access ecuAbstraction;

		protected RecManDataLogger datlogA;

		protected RecManDataLogger datlogB;

		private LiveView liveViewA;

		private LiveView liveViewB;

		private Xml_Log LiveViewLog;

		private static CryptedCompression cryptedCompression = new CryptedCompression();

		private string[] IQA_Cyl_WriteText = new string[4] { " ", " ", " ", " " };

		private string[] IQA_CylA_ReadText = new string[4] { " ", " ", " ", " " };

		private string[] IQA_CylB_ReadText = new string[4] { " ", " ", " ", " " };

		private bool LiveViewCfg_AuxEnabled;

		private string LiveViewCfg_AuxAddress;

		private int LiveViewCfg_AuxLength;

		private bool LiveViewCfg_ExpertEnable;

		private int LiveViewCfg_RecInterval_ms;

		private List<string> LiveViewCfg_sigDescA;

		private List<string> LiveViewCfg_sigDescB;

		private string LiveView_LogPath = "";

		private string sessionLogFilePathAndNameA = "";

		private string sessionLogFilePathAndNameB = "";

		private MemoryStream originalStream;

		private static byte[] bufUnModified = new byte[ConfigData.DatLogMemorySize_si];

		private static byte[] bufZipped = new byte[ConfigData.DatLogMemorySize_si / 10];

		private static byte[] bufEncrypted = new byte[ConfigData.DatLogMemorySize_si / 10];

		private Engine12 engineMsgA;

		private Engine12 engineMsgB;

		private ThreadManager threadManager;

		private bool logECUA = true;

		private bool logECUB = true;

		private ConfigData.ECUCONNECTED connectInfosaved;

		private List<GaphObj> GraphServicesList = new List<GaphObj>();

		public string myLogPath;

		public Xml_Log.CXmlFileLogInfo dataLogInfo;

		private static string currentLogPath;

		private Xml_Log DataLog;

		private object[] grArr = new object[10];

		private FlashLayer flashLayer;

		private ScriptingInterface scriptInterface;

		public RecManDataLogger DatlogA
		{
			get
			{
				return datlogA;
			}
		}

		public RecManDataLogger DatlogB
		{
			get
			{
				return datlogB;
			}
		}

		public Engine12 EngineMsgA
		{
			get
			{
				return engineMsgA;
			}
			set
			{
				engineMsgA = value;
			}
		}

		public Engine12 EngineMsgB
		{
			get
			{
				return engineMsgB;
			}
			set
			{
				engineMsgB = value;
			}
		}

		public BaseService BaseServiceB
		{
			get
			{
				return baseServiceB;
			}
		}

		public BaseService BaseServiceA
		{
			get
			{
				return baseServiceA;
			}
		}

		public FlashLayer FlashLayer
		{
			get
			{
				return flashLayer;
			}
			set
			{
				flashLayer = value;
			}
		}

		public event EventHandler<ServiceLayerStringEventArg> ev_ProgressStep;

		public event EventHandler<ServiceLayerBoolEventArg> ev_ProgressClose;

		public event EventHandler ev_FormClose;

		public event BaseService.AddConsoleHandler ev_AddConsoleEvent;

		public event EventHandler ev_StatisticsUpdated;

		public event EventHandler ev_EngineLogUpdated;

		public event SecurityDongleCodeHandler ev_SecurityReEvaluateRights;

		public event EventHandler<ServiceLayerStringEventArg> ev_ProgressTimerSetup;

		public event EventHandler<ServiceLayerStringEventArg> ev_ProgressTimerInfoText;

		public event EventHandler<ServiceLayerStringEventArg> ev_ProgressSetup;

		public event EventHandler ev_SessionLogTriggerSave;

		public event EventHandler ev_SessionLogSaveCautionLamp;

		public event EventHandler ev_DTCDataRefreshed;

		public event EventHandler ev_IQADataCylReadUpdated;

		public event EventHandler ev_IQADataCylWriteUpdated;

		public event LiveViewConfigDataLoadedHandler ev_LiveViewConfigLoaded;

		private event EventHandler<ServiceLayerProcessTypeEventArg> ev_ProcessFinished;

		private event EventHandler<ServiceLayerProcessTypeEventArg> ev_ProcessError;

		public ServiceLayer()
		{
			ecuAbstraction = new ECU_Access();
			ecuAbstraction.ev_AddConsoleEvent += ecuAbstraction_ev_AddConsoleEvent;
			baseServiceA = new BaseService(ConfigData.e_ECUID.A, ecuAbstraction);
			baseServiceB = new BaseService(ConfigData.e_ECUID.B, ecuAbstraction);
			baseServiceA.ev_AddConsoleEvent += baseService_AddConsoleEvent;
			baseServiceB.ev_AddConsoleEvent += baseService_AddConsoleEvent;
			baseServiceA.ev_LogFehler += baseService_ev_LogFehler;
			baseServiceB.ev_LogFehler += baseService_ev_LogFehler;
			engineMsgA = new Engine12(ecuAbstraction.AddMessage(new CANMessage((uint)(768 + ConfigData.ECU_Nr), 0u, 0u, 8, 0u, "ENG1A", 1)), ecuAbstraction.AddMessage(new CANMessage((uint)(784 + ConfigData.ECU_Nr), 0u, 0u, 8, 0u, "ENG2A", 1)));
			engineMsgB = new Engine12(ecuAbstraction.AddMessage(new CANMessage((uint)(1024 + ConfigData.ECU_Nr), 0u, 0u, 8, 0u, "ENG1B", 1)), ecuAbstraction.AddMessage(new CANMessage((uint)(1040 + ConfigData.ECU_Nr), 0u, 0u, 8, 0u, "ENG2B", 1)));
			threadManager = new ThreadManager();
			flashLayer = new FlashLayer(baseServiceA, baseServiceB, new FlashService(baseServiceA), new FlashService(baseServiceB), engineMsgA, engineMsgB);
			flashLayer.ev_AddConsoleEvent += servicelayer_ev_AddConsole;
			flashLayer.ev_DTC_Clear += flashLayer_ev_DTC_Clear;
			flashLayer.ev_DTC_Read += flashLayer_ev_DTC_Read;
			flashLayer.ev_EngLog_Save += flashLayer_ev_EngLog_Save;
			flashLayer.ev_EEPROM_BackupTrigger += flashLayer_ev_EEPROM_BackupTrigger;
			flashLayer.ev_EEPROM_RestoreTrigger += flashLayer_ev_EEPROM_RestoreTrigger;
			flashLayer.ev_LogAddEngineID += flashLayer_ev_LogAddEngineID;
			flashLayer.ev_SessionLogTriggerSave += flashLayer_ev_SessionLogTriggerSave;
			ev_ProcessFinished += flashLayer.h_ProcessFinished;
			ev_ProcessError += flashLayer.h_ProcessError;
			if (!ecuAbstraction.ConnectUSB() && this.ev_AddConsoleEvent != null)
			{
				this.ev_AddConsoleEvent("Could not open CANUSBDongle.CAN1", Color.Black, "");
			}
		}

		private void ecuAbstraction_ev_AddConsoleEvent(string s, string AB)
		{
			baseService_AddConsoleEvent(s, Color.Black, AB);
		}

		private void flashLayer_ev_DTC_Read(object sender, EventArgs e)
		{
			if (!ECU_TryToConnect())
			{
				this.ev_ProcessError(this, new ServiceLayerProcessTypeEventArg(ConfigData.e_WizardProcesses.DTC_READ));
			}
			else
			{
				TH_DTCRead(new object());
			}
		}

		private void flashLayer_ev_EngLog_Save(object sender, ServiceLayerStringEventArg e)
		{
			EngLogSave(ConfigData.LogRootPath + "\\Engine_Log\\" + e.Message);
		}

		private void flashLayer_ev_DTC_Clear(object sender, EventArgs e)
		{
			if (!ECU_TryToConnect())
			{
				this.ev_ProcessError(this, new ServiceLayerProcessTypeEventArg(ConfigData.e_WizardProcesses.DTC_CLEAR));
			}
			else
			{
				DTC_Clear(false);
			}
		}

		private void flashLayer_ev_LogAddEngineID(object sender, ServiceLayerStreamEventArg e)
		{
			originalStream = (MemoryStream)e.Strm;
			Xml_Log xml_Log = new Xml_Log();
			try
			{
				xml_Log.CreateLogStream(originalStream, "ENGINE_LOG", true);
				xml_Log.FileID(Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(e.Filename)) + ".xml");
				xml_Log.SwID(ConfigData.WizardSwName, ConfigData.WizardSwVersion, ConfigData.WizardManufacturer, ConfigData.EcuVersionsStrings[(uint)ConfigData.ecuSwVersion]);
				xml_Log.UserID();
				TH_EngineIDSave(xml_Log);
				xml_Log.EndLog_KeepStreamUp();
				flashLayer.FlashLog_EngineID_Completed = true;
			}
			catch (Exception)
			{
			}
		}

		private void flashLayer_ev_EEPROM_RestoreTrigger(object sender, EventArgs e)
		{
			throw new NotImplementedException();
		}

		private void flashLayer_ev_EEPROM_BackupTrigger(object sender, ServiceLayerStreamEventArg e)
		{
			EEPROM_Backup_SaveXML(e.Strm);
		}

		private void flashLayer_ev_SessionLogTriggerSave(object sender, EventArgs e)
		{
			if (this.ev_SessionLogTriggerSave != null)
			{
				this.ev_SessionLogTriggerSave(sender, e);
			}
		}

		private void baseService_ev_LogFehler(string AB, string fehler)
		{
			if (this.ev_AddConsoleEvent != null)
			{
				this.ev_AddConsoleEvent(fehler, Color.Black, "ECU " + AB + ":  ");
			}
		}

		public static bool EvaluateFileType(Stream stream, ConfigData.e_FileTypes validType)
		{
			Xml_Log xml_Log = new Xml_Log();
			bool result = false;
			ConfigData.e_FileTypes e_FileTypes = xml_Log.ReadFiletype(stream);
			stream.Close();
			if (validType == ConfigData.e_FileTypes.IQA)
			{
				switch (e_FileTypes)
				{
				case ConfigData.e_FileTypes.IQA_STORAGE:
					result = true;
					MessageBox.Show("Info: File type is IQA storage!", ConfigData.WizardSwName, MessageBoxButtons.OK, MessageBoxIcon.Question);
					break;
				case ConfigData.e_FileTypes.IQA:
					result = true;
					break;
				}
			}
			else if (e_FileTypes != validType)
			{
				MessageBox.Show("File is not a valid " + validType.ToString() + " - File\r\nIt's of type: " + e_FileTypes, ConfigData.WizardSwName);
			}
			else
			{
				result = true;
			}
			return result;
		}

		public void LiveViewSetup(ref List<int> sigDescIntsA, ref List<int> sigDescIntsB, int recInterval_ms, bool AuxSigEnabled, string AuxAdr, int AuxLength, bool enableINCAExport, ConfigData.ETests testType)
		{
			GaphObj gaphObj = new GaphObj(EGrapphObjType.eLiveViewGraphType);
			UIGraphWindow uiGrp = new UIGraphWindow(new UIGraphLiveView(ConfigBase.EGraphicAspect.eShowGraphLiveView));
			UIGraphWindow uIGraphWindow = uiGrp;
			string text = uIGraphWindow.Text;
			uIGraphWindow.Text = text + ConfigData.WizardSwName + " " + ConfigData.WizardSwVersion + " " + uiGrp.Text;
			LiveView lvA = new LiveView(baseServiceA);
			LiveView lvB = new LiveView(baseServiceB);
			LiveViewInit(ref lvA, ref lvB);
			uiGrp.MinimumSize = new Size(1040, 617);
			uiGrp.Size = new Size(1040, 617);
			uiGrp.Icon = Resources.window_app_graph1;
			uiGrp.UiGraph1.toolStripButtonStop.Enabled = false;
			LogSignalLiveView liveViewSignal_ByName = ConfigLiveView.GetLiveViewSignal_ByName("Aux_signal", ConfigData.e_ECUID.A);
			baseServiceA.EcuData.LiveViewSignals.Clear();
			baseServiceB.EcuData.LiveViewSignals.Clear();
			baseServiceA.EcuData.LiveViewSignals.Capacity = 12 + sigDescIntsA.Count;
			baseServiceB.EcuData.LiveViewSignals.Capacity = 12 + sigDescIntsB.Count;
			lvA.RecordInterval_ms = recInterval_ms;
			lvB.RecordInterval_ms = recInterval_ms;
			int num = 0;
			baseServiceA.EcuData.LiveViewVirtualSignals = new List<ConfigLiveView.LiveViewVirtualSig>();
			baseServiceB.EcuData.LiveViewVirtualSignals = new List<ConfigLiveView.LiveViewVirtualSig>();
			foreach (int item2 in sigDescIntsA)
			{
				LogSignalLiveView liveViewSignalA_ByIndex = ConfigLiveView.GetLiveViewSignalA_ByIndex(item2);
				baseServiceA.EcuData.LiveViewSignals.Add(liveViewSignalA_ByIndex);
				if (liveViewSignalA_ByIndex.IsSignalVirtual)
				{
					ConfigLiveView.LiveViewVirtualSig item = ConfigLiveView.virtualLiveViewSignalsA[ConfigLiveView.findVirtSigA(item2)];
					if (item.sigNr1 != 172)
					{
						item.sigNr1 = SetPosOfInputSign(ref sigDescIntsA, item.sigNr1);
					}
					if (item.sigNr2 != 172)
					{
						item.sigNr2 = SetPosOfInputSign(ref sigDescIntsA, item.sigNr2);
					}
					baseServiceA.EcuData.LiveViewVirtualSignals.Add(item);
				}
				num++;
			}
			num = 0;
			foreach (int item3 in sigDescIntsB)
			{
				LogSignalLiveView liveViewSignalA_ByIndex = ConfigLiveView.GetLiveViewSignalB_ByIndex(item3);
				baseServiceB.EcuData.LiveViewSignals.Add(liveViewSignalA_ByIndex);
				if (liveViewSignalA_ByIndex.IsSignalVirtual)
				{
					ConfigLiveView.LiveViewVirtualSig item = ConfigLiveView.virtualLiveViewSignalsB[ConfigLiveView.findVirtSigA(item3)];
					if (item.sigNr1 != 172)
					{
						item.sigNr1 = SetPosOfInputSign(ref sigDescIntsB, item.sigNr1);
					}
					if (item.sigNr2 != 172)
					{
						item.sigNr2 = SetPosOfInputSign(ref sigDescIntsB, item.sigNr2);
					}
					baseServiceB.EcuData.LiveViewVirtualSignals.Add(item);
				}
				num++;
			}
			if (AuxSigEnabled)
			{
				liveViewSignal_ByName.ConfigureAuxSignal(AuxAdr, AuxLength);
				baseServiceA.EcuData.LiveViewSignals.Add(liveViewSignal_ByName);
				baseServiceB.EcuData.LiveViewSignals.Add(liveViewSignal_ByName);
			}
			LiveViewSetupInternal(ref lvA, ref lvB, recInterval_ms, ref uiGrp);
			((UIGraphLiveView)uiGrp.UiGraph1).ev_RecordButtonPressed += LiveViewRecordStart;
			((UIGraphLiveView)uiGrp.UiGraph1).ev_StopButtonPressed += LiveViewRecordStop;
			uiGrp.AbortThread += uigrphWin_AbortThread;
			uiGrp.UiGraph1.myListNr = GraphServicesList.Count;
			uiGrp.Show();
			gaphObj.recManA = lvA;
			gaphObj.recManB = lvB;
			gaphObj.uiGraph = uiGrp;
			GraphServicesList.Add(gaphObj);
		}

		public void LiveViewRecordStart(object inWin, EventArgs e)
		{
			UIGraphLiveView uIGraphLiveView = (UIGraphLiveView)inWin;
			GaphObj gaphObj = GraphServicesList[uIGraphLiveView.myListNr];
			gaphObj.logPath = uIGraphLiveView.MyFileName;
			originalStream = new MemoryStream(bufUnModified, 0, bufUnModified.Length, true, true);
			originalStream.SetLength(0L);
			LiveView liveView = (LiveView)gaphObj.recManA;
			LiveView liveView2 = (LiveView)gaphObj.recManB;
			Xml_Log xml_Log = new Xml_Log();
			if (liveView != null && liveView2 != null)
			{
				try
				{
					LiveView_LogPath = gaphObj.logPath;
					List<string> list = new List<string>();
					List<string> list2 = new List<string>();
					xml_Log.CreateLogStream("LIVEVIEW", false);
					xml_Log.FileID(Path.GetFileName(gaphObj.logPath));
					xml_Log.SwID(ConfigData.WizardSwName, ConfigData.WizardSwVersion, ConfigData.WizardManufacturer, ConfigData.EcuVersionsStrings[(uint)ConfigData.ecuSwVersion]);
					xml_Log.UserID();
					xml_Log.SaveEngineID(baseServiceA.EcuData, baseServiceB.EcuData);
					xml_Log.SaveLiveViewHeader();
					xml_Log.SaveLiveViewRecordInterval(liveView.RecordInterval_ms, "A");
					xml_Log.SaveLiveViewRecordInterval(liveView2.RecordInterval_ms, "B");
					foreach (LogSignalLiveView liveViewSignal in baseServiceA.EcuData.LiveViewSignals)
					{
						list.Add(liveViewSignal.Ecu_Message);
					}
					foreach (LogSignalLiveView liveViewSignal2 in baseServiceB.EcuData.LiveViewSignals)
					{
						list2.Add(liveViewSignal2.Ecu_Message);
					}
					if (LiveViewCfg_AuxEnabled)
					{
						xml_Log.SaveLiveViewSignalDef(list, "A", LiveViewCfg_AuxAddress, Convert.ToInt32(LiveViewCfg_AuxLength));
						xml_Log.SaveLiveViewSignalDef(list2, "B", LiveViewCfg_AuxAddress, Convert.ToInt32(LiveViewCfg_AuxLength));
					}
					else
					{
						xml_Log.SaveLiveViewSignalDef(list, "A");
						xml_Log.SaveLiveViewSignalDef(list2, "B");
					}
					xml_Log.SaveLiveViewSamplesHeader();
					liveView.XmlLog = xml_Log;
					liveView2.XmlLog = xml_Log;
					liveView.ButtonRecordPressed_Handler(EngineMsgA, uIGraphLiveView);
					liveView2.ButtonRecordPressed_Handler(EngineMsgB, uIGraphLiveView);
					gaphObj.recManA = liveView;
					gaphObj.recManB = liveView2;
					gaphObj.uiGraph = uIGraphLiveView;
					return;
				}
				catch (Exception ex)
				{
					if (liveView.XmlLog != null)
					{
						liveView.XmlLog.Close();
					}
					MessageBox.Show("Warning: LiveView save-process failed!\r\n" + ex.Message, ConfigData.WizardSwName);
					if (liveView != null)
					{
						liveView.RecordStop();
					}
					if (liveView2 != null)
					{
						liveView2.RecordStop();
					}
					if (this.ev_SessionLogTriggerSave != null)
					{
						this.ev_SessionLogTriggerSave(this, null);
					}
					if (this.ev_SecurityReEvaluateRights != null)
					{
						this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
					}
					return;
				}
			}
			MessageBox.Show("Warning: LiveView save-process failed!\r\nInstance == null!\r\n", ConfigData.WizardSwName);
		}

		private void LiveViewRecordingStoppedHandler(object sender, EventArgs e)
		{
			lock (sender)
			{
				if (!((Xml_Log)sender).IsClosed())
				{
					if (LiveView_LogPath.Length == 0)
					{
						MessageBox.Show("LiveView: Error when writing record data to file, no filename provided!");
						return;
					}
					((Xml_Log)sender).SaveLiveViewFooter();
					((Xml_Log)sender).EndLog();
					SecurityEncryptToFile(LiveView_LogPath, originalStream);
				}
			}
		}

		public void LiveViewRecordStop(object sender, UIGraphWindowListNr e)
		{
			int myNr = e.myNr;
			GaphObj gaphObj = GraphServicesList[myNr];
			LiveView liveView = (LiveView)gaphObj.recManA;
			LiveView liveView2 = (LiveView)gaphObj.recManB;
			Console.WriteLine("LiveViewRecordStop: graphObj = GraphServicesList[ {0} ]", myNr);
			UIGraphLiveView uIGraphLiveView = (UIGraphLiveView)gaphObj.uiGraph;
			liveView.RecordStop();
			liveView2.RecordStop();
			if (liveView.XmlLog != null)
			{
				lock (liveView.XmlLog)
				{
					if (!liveView.XmlLog.IsClosed())
					{
						liveView.XmlLog.SaveLiveViewFooter();
						liveView.XmlLog.EndLog();
						SecurityEncryptToFile(gaphObj.logPath, liveView.XmlLog.myStream);
					}
				}
			}
			else if (liveView2.XmlLog != null)
			{
				lock (liveView2.XmlLog)
				{
					if (!liveView2.XmlLog.IsClosed())
					{
						liveView.XmlLog.SaveLiveViewFooter();
						liveView.XmlLog.EndLog();
						SecurityEncryptToFile(gaphObj.logPath, liveView.XmlLog.myStream);
					}
				}
			}
			if (baseServiceA.BaseServSecurityAccessRight() == ConfigSecurity.e_USBDongleTypes.OEM || baseServiceA.BaseServSecurityAccessRight() == ConfigSecurity.e_USBDongleTypes.WDAE)
			{
				uIGraphLiveView.toolStripButtonExportVisible(true);
				uIGraphLiveView.toolStripButtonExportEnabled(true);
			}
			else
			{
				uIGraphLiveView.toolStripButtonExportVisible(false);
				uIGraphLiveView.toolStripButtonExportEnabled(false);
			}
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
		}

		private void LiveViewRecordingErrorHandler(object sender, EventArgs e)
		{
			liveViewA.RecordStop();
			liveViewB.RecordStop();
			MessageBox.Show("Error during LiveView-recording process.\nXML data has been saved and recording has been stopped!\r\nError in: " + (string)sender, ConfigData.WizardSwName);
		}

		private void baseService_AddConsoleEvent(string s, Color c, string AB)
		{
			if (this.ev_AddConsoleEvent != null)
			{
				this.ev_AddConsoleEvent(s, c, AB);
			}
		}

		public void ShutdownServices()
		{
			threadManager.AddTask(TH_ShutdownServices, new object());
		}

		public bool ECU_VerifyBothConnected()
		{
			if (!baseServiceA.ECUisOnline() && !baseServiceB.ECUisOnline())
			{
				MessageBox.Show(ConfigData.WizardSwName + " is not connected!", ConfigData.WizardSwName);
				return false;
			}
			if (!baseServiceA.ECUisOnline())
			{
				MessageBox.Show("ECU A is not connected!\r\nPlease re-establish connection!", ConfigData.WizardSwName);
				return false;
			}
			if (!baseServiceB.ECUisOnline())
			{
				MessageBox.Show("ECU B is not connected!\r\nPlease re-establish connection!", ConfigData.WizardSwName);
				return false;
			}
			return true;
		}

		public void ECU_ECUCheckBox(bool chk, ConfigData.e_ECUID ecu)
		{
			switch (ecu)
			{
			case ConfigData.e_ECUID.A:
				logECUA = chk;
				break;
			case ConfigData.e_ECUID.B:
				logECUB = chk;
				break;
			}
		}

		public ConfigData.ECUCONNECTED ECU_VerifyECUConnected()
		{
			ConfigData.ECUCONNECTED eCUCONNECTED = ConfigData.ECUCONNECTED.e_ECU_NOT_CONNECTED;
			if (baseServiceA.ECUisOnline())
			{
				eCUCONNECTED = ConfigData.ECUCONNECTED.e_ECU_A_CONNECTED;
			}
			if (baseServiceB.ECUisOnline())
			{
				eCUCONNECTED = ((eCUCONNECTED != ConfigData.ECUCONNECTED.e_ECU_A_CONNECTED) ? ConfigData.ECUCONNECTED.e_ECU_B_CONNECTED : ConfigData.ECUCONNECTED.e_ECU_ALL_CONNECTED);
			}
			if ((int)connectInfosaved < (int)eCUCONNECTED)
			{
				switch (eCUCONNECTED)
				{
				case ConfigData.ECUCONNECTED.e_ECU_A_CONNECTED:
					MessageBox.Show("ECU B is not connected!\r\nPlease re-establish connection!", ConfigData.WizardSwName);
					break;
				case ConfigData.ECUCONNECTED.e_ECU_B_CONNECTED:
					MessageBox.Show("ECU A is not connected!\r\nPlease re-establish connection!", ConfigData.WizardSwName);
					break;
				}
				connectInfosaved = eCUCONNECTED;
			}
			return eCUCONNECTED;
		}

		public void AbortThread(bool killThreadManager)
		{
			threadManager.AbortTasks(killThreadManager);
			flashLayer.AbortThread();
		}

		public void DatLog_LoadXML(string logpath)
		{
			bool flag = true;
			GaphObj gaphObj = new GaphObj(EGrapphObjType.eDataLogGraphType);
			gaphObj.logPath = logpath;
			int i;
			for (i = 0; i < GraphServicesList.Count; i++)
			{
				if (!flag)
				{
					break;
				}
				GaphObj gaphObj2 = GraphServicesList[i];
				if (gaphObj2.grphType == EGrapphObjType.eNoGraphObjType)
				{
					flag = false;
				}
			}
			i = (flag ? GraphServicesList.Count : (i - 1));
			UIGraphWindow uIGraphWindow = new UIGraphWindow(new UIGraphDatLog());
			uIGraphWindow.Text = ConfigData.WizardSwName + " " + ConfigData.WizardSwVersion + "  " + uIGraphWindow.Text + ": " + Path.GetFileName(logpath);
			uIGraphWindow.MinimumSize = new Size(1080, 617);
			uIGraphWindow.Size = new Size(1080, 637);
			uIGraphWindow.Icon = Resources.window_app_graph1;
			uIGraphWindow.SizeChanged += uIGraphWindow.UiGraph1.ResizeUiGraph1;
			uIGraphWindow.FormClosing += uigraphwindow_FormClosing;
			uIGraphWindow.UiGraph1.myListNr = i;
			uIGraphWindow.Show();
			gaphObj.uiGraph = uIGraphWindow;
			if (!flag)
			{
				GraphServicesList[i] = gaphObj;
			}
			else
			{
				GraphServicesList.Add(gaphObj);
			}
			threadManager.AddTask(TH_DataLogLoadXML, i);
		}

		public void DatLog_SaveXML(string logpath)
		{
			DatLog_Init();
			RecManBase.CInDumpData cInDumpData = new RecManBase.CInDumpData();
			cInDumpData.logPath = logpath;
			cInDumpData.blckCnt = 140;
			cInDumpData.thProcType = ConfigData.EHexDumpProc.eReadDatLogAll;
			threadManager.AddTask(TH_HexDumpToXML, cInDumpData);
		}

		public void DatLog_SaveXML(string logpath, int hours)
		{
			DatLog_Init();
			RecManBase.CInDumpData cInDumpData = new RecManBase.CInDumpData();
			cInDumpData.logPath = logpath;
			cInDumpData.blckCnt = (int)((double)hours / ConfigRecMan.DatLogHoursPerSector) + 1;
			if (cInDumpData.blckCnt < 4)
			{
				cInDumpData.blckCnt = 4;
			}
			cInDumpData.thProcType = ConfigData.EHexDumpProc.eReadDatLogHours;
			threadManager.AddTask(TH_HexDumpToXML, cInDumpData);
		}

		public void DatLog_SaveXML(string logpath, int minSector, int maxSector)
		{
			DatLog_Init();
			RecManBase.CInDumpData cInDumpData = new RecManBase.CInDumpData();
			cInDumpData.logPath = logpath;
			cInDumpData.blckCnt = maxSector - minSector + 1;
			cInDumpData.sectorsNrList = new List<int>(cInDumpData.blckCnt);
			for (int num = maxSector; num >= minSector; num--)
			{
				cInDumpData.sectorsNrList.Add(num);
			}
			cInDumpData.thProcType = ConfigData.EHexDumpProc.eHexDumpProc;
			threadManager.AddTask(TH_HexDumpToXML, cInDumpData);
		}

		private void TH_ReadEngLogEvRecDatLog(object hours)
		{
			string arg = DateTime.UtcNow.ToString("yyyyMMdd");
			DatLog_Init();
			string logRootPath = ConfigData.LogRootPath;
			ECU_VerifyECUConnected();
			string file = string.Format("{0}\\Engine_Log\\Engine_Log_{1}.ae3", logRootPath, arg);
			TH_EngLogSaveStream(file);
			Thread.Sleep(1500);
			RecManBase.CInDumpData cInDumpData = new RecManBase.CInDumpData();
			cInDumpData.logPath = string.Format("{0}\\HexDump\\EvRec_{1}.ae3", logRootPath, arg);
			cInDumpData.blckCnt = 32;
			cInDumpData.thProcType = ConfigData.EHexDumpProc.eReadEventsAll;
			ConfigData.SUIProgressbar sUIProgressbar = new ConfigData.SUIProgressbar();
			sUIProgressbar.msg = "Saving valid EvRec-sectors to XML_Log...\nThis might take several minutes, \ndepending on the number of written sectors...";
			sUIProgressbar.val = 62;
			if (this.ev_ProgressSetup != null)
			{
				this.ev_ProgressSetup(this, new ServiceLayerStringEventArg(sUIProgressbar));
			}
			TH_HexDumpToXML(cInDumpData);
			Thread.Sleep(3500);
			file = string.Format("{0}\\HexDump\\DataLog_{1}.ae3", logRootPath, arg);
			cInDumpData = new RecManBase.CInDumpData();
			cInDumpData.logPath = file;
			cInDumpData.blckCnt = (int)((double)(int)hours / ConfigRecMan.DatLogHoursPerSector) + 1;
			if (cInDumpData.blckCnt < 4)
			{
				cInDumpData.blckCnt = 4;
			}
			cInDumpData.sectorsNrList = new List<int>();
			cInDumpData.thProcType = ConfigData.EHexDumpProc.eReadDatLogHours;
			Console.WriteLine("Start TH_HexDumpToXML !!!");
			sUIProgressbar.msg = "Downloading of data logger data from both ECUs \ncombined takes about 1 min per 2h of recorded flight time\n(max. download time about 40min)";
			sUIProgressbar.val = (int)hours + 2;
			if (this.ev_ProgressSetup != null)
			{
				this.ev_ProgressSetup(this, new ServiceLayerStringEventArg(sUIProgressbar));
			}
			TH_HexDumpToXML(cInDumpData);
		}

		public void DatLog_Init()
		{
			datlogA = new RecManDataLogger(baseServiceA);
			datlogB = new RecManDataLogger(baseServiceB);
			datlogA.ev_AddConsole += servicelayer_ev_AddConsole;
			datlogA.ev_ProgressClose += servicelayer_ev_ProgressClose;
			datlogA.ev_ProgressStep += servicelayer_ev_ProgressStep;
			datlogB.ev_AddConsole += servicelayer_ev_AddConsole;
			datlogB.ev_ProgressClose += servicelayer_ev_ProgressClose;
			datlogB.ev_ProgressStep += servicelayer_ev_ProgressStep;
		}

		private void uigraphwindow_FormClosing(object sender, FormClosingEventArgs e)
		{
			try
			{
				UIGraphWindow uIGraphWindow = (UIGraphWindow)sender;
				GaphObj gaphObj = GraphServicesList[uIGraphWindow.UiGraph1.myListNr];
				gaphObj.grphType = EGrapphObjType.eNoGraphObjType;
				RecManDataLogger recManDataLogger = (RecManDataLogger)gaphObj.recManA;
				recManDataLogger.ev_UpdateData -= uIGraphWindow.UiGraph1.UpdateData;
				recManDataLogger.ev_NewVar -= uIGraphWindow.UiGraph1.Addvar;
				recManDataLogger = (RecManDataLogger)gaphObj.recManB;
				recManDataLogger.ev_UpdateData -= uIGraphWindow.UiGraph1.UpdateData;
				recManDataLogger.ev_NewVar -= uIGraphWindow.UiGraph1.Addvar;
				AbortThread(false);
				DatLog_Close();
				uIGraphWindow.Dispose();
				gaphObj.uiGraph = null;
				gaphObj.logPath = null;
				recManDataLogger = (RecManDataLogger)gaphObj.recManA;
				recManDataLogger.Dispose();
				recManDataLogger = (RecManDataLogger)gaphObj.recManB;
				recManDataLogger.Dispose();
				gaphObj.recManA = null;
				gaphObj.recManB = null;
				GC.Collect(2);
			}
			catch
			{
			}
		}

		public void UIEvents_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (sender is UIEvents)
			{
				UIEvents uIEvents = (UIEvents)sender;
				uIEvents.UIEvents_FormClosing();
				GaphObj gaphObj = GraphServicesList[uIEvents.myListNr];
				gaphObj.logPath = null;
				gaphObj.recManA = null;
				gaphObj.recManB = null;
				gaphObj.grphType = EGrapphObjType.eNoGraphObjType;
			}
			GC.Collect(2);
		}

		private void DatLog_Close()
		{
		}

		public void EvRec_LoadXML(string logpath)
		{
			bool flag = true;
			GaphObj gaphObj = new GaphObj(EGrapphObjType.eEventRecGraphType);
			int i;
			for (i = 0; i < GraphServicesList.Count; i++)
			{
				if (!flag)
				{
					break;
				}
				GaphObj gaphObj2 = GraphServicesList[i];
				if (gaphObj2.grphType == EGrapphObjType.eNoGraphObjType)
				{
					flag = false;
				}
			}
			i = (flag ? GraphServicesList.Count : (i - 1));
			UIEvents uIEvents = new UIEvents(i);
			uIEvents.dataGridView1.Rows.Clear();
			uIEvents.Text = ConfigData.WizardSwName + " " + ConfigData.WizardSwVersion + "   " + uIEvents.Text + ": " + logpath;
			gaphObj.logPath = logpath;
			uIEvents.Show();
			uIEvents.FormClosing += UIEvents_FormClosing;
			gaphObj.uiGraph = uIEvents;
			if (!flag)
			{
				GraphServicesList[i] = gaphObj;
			}
			else
			{
				GraphServicesList.Add(gaphObj);
			}
			threadManager.AddTask(TH_EvRecLoadXML, i);
		}

		public void DTC_Read()
		{
			if (ECU_VerifyBothConnected())
			{
				threadManager.AddTask(TH_DTCRead, new object());
			}
		}

		public void DTC_Clear(bool DTC_read_precheck)
		{
			threadManager.AddTask(TH_DTCClear, DTC_read_precheck);
		}

		public void EvRec_SaveXML(string logpath)
		{
			DatLog_Init();
			RecManBase.CInDumpData cInDumpData = new RecManBase.CInDumpData();
			cInDumpData.logPath = logpath;
			cInDumpData.blckCnt = 32;
			cInDumpData.thProcType = ConfigData.EHexDumpProc.eReadEventsAll;
			threadManager.AddTask(TH_HexDumpToXML, cInDumpData);
		}

		public void Statistics_Read()
		{
			if (ECU_VerifyBothConnected())
			{
				threadManager.AddTask(TH_StatisticsRead, new object());
			}
		}

		public void Statistics_Reset()
		{
			threadManager.AddTask(TH_StatisticsReset, new object());
		}

		public void ECU_Connect()
		{
			if (baseServiceA.ECUisOnline() && baseServiceB.ECUisOnline())
			{
				MessageBox.Show("Connection already established", ConfigData.WizardSwName);
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
			}
			else
			{
				threadManager.AddTask(TH_ECUConnect, new object());
			}
		}

		public void IQA_LoadXML(string logpath)
		{
			threadManager.AddTask(TH_IQALoadXML, logpath);
		}

		public void IQA_SaveXML(string logpath, string[] iqaCodesA, string[] iqaCodesB)
		{
			if (iqaCodesA.Length != 4 || iqaCodesB.Length != 4)
			{
				MessageBox.Show("Internal error: \r\nServicelayer.IQA_SaveXML:\nIQA-string array does not match length constraint!", ConfigData.WizardSwName);
				return;
			}
			lock (IQA_CylA_ReadText.SyncRoot)
			{
				IQA_CylA_ReadText = iqaCodesA;
			}
			lock (IQA_CylB_ReadText.SyncRoot)
			{
				IQA_CylB_ReadText = iqaCodesB;
			}
			threadManager.AddTask(TH_IQASaveXML, logpath);
		}

		public void IQA_CylRead(ConfigData.e_IQACylinder cylIndex)
		{
			threadManager.AddTask(TH_IQACylRead, ConfigData.GetIQACylCode(cylIndex));
		}

		public void IQA_CylWrite(List<byte[]> cylTextArr)
		{
			threadManager.AddTask(TH_IQACylWrite, cylTextArr);
		}

		public void IQA_CylWriter(ConfigData.e_IQACylinder cylIndex, string[] cylTextArray)
		{
			if (cylTextArray.GetLength(0) != 4)
			{
				MessageBox.Show("Internal error:\r\nNr. of strings for writing IQA-codes invalid!", ConfigData.WizardSwName);
				return;
			}
			lock (IQA_Cyl_WriteText.SyncRoot)
			{
				IQA_Cyl_WriteText = cylTextArray;
			}
			threadManager.AddTask(TH_IQACylWrite, cylIndex);
		}

		public void IQA_Init1()
		{
			threadManager.AddTask(TH_IQA_Init_1, new object());
		}

		public void IQA_Init2()
		{
			threadManager.AddTask(TH_IQA_Init_2, new object());
		}

		public void LiveViewLoadXML(string logpath)
		{
			GaphObj gaphObj = new GaphObj(EGrapphObjType.eLiveViewGraphType);
			gaphObj.logPath = logpath;
			UIGraphWindow uIGraphWindow = new UIGraphWindow(new UIGraphLiveView(ConfigBase.EGraphicAspect.eShowGraphLiveViewRec));
			uIGraphWindow.Text = ConfigData.WizardSwName + " " + ConfigData.WizardSwVersion + "   " + uIGraphWindow.Text + ": " + Path.GetFileName(logpath);
			uIGraphWindow.MinimumSize = new Size(1040, 617);
			uIGraphWindow.Size = new Size(1040, 617);
			uIGraphWindow.SizeChanged += uIGraphWindow.UiGraph1.ResizeUiGraph1;
			uIGraphWindow.Icon = Resources.window_app_graph1;
			uIGraphWindow.UiGraph1.myListNr = GraphServicesList.Count;
			uIGraphWindow.UiGraph1.MyFileName = logpath;
			if (baseServiceA.BaseServSecurityAccessRight() == ConfigSecurity.e_USBDongleTypes.OEM)
			{
				uIGraphWindow.UiGraph1.toolStripButtonExportEnabled(true);
			}
			else
			{
				uIGraphWindow.UiGraph1.toolStripButtonExportEnabled(false);
			}
			uIGraphWindow.UiGraph1.toolStripButtonStop.Visible = false;
			uIGraphWindow.UiGraph1.toolStripButtonRecord.Visible = false;
			uIGraphWindow.Show();
			gaphObj.uiGraph = uIGraphWindow;
			GraphServicesList.Add(gaphObj);
			threadManager.AddTask(TH_LiveViewLoadXML, GraphServicesList.Count - 1);
		}

		public void LiveViewLoadConfigXML(string logpath)
		{
			threadManager.AddTask(TH_LiveViewLoadConfig, logpath);
		}

		public void LiveViewSaveConfigXML(string logpath, int recordInterval_ms, bool LiveViewCfg_ExpertEnabled, bool LiveViewCfg_AuxEnabled, string LiveViewCfg_AuxAddress, int LiveViewCfg_AuxLength, List<string> LiveViewCfg_sigDescA, List<string> LiveViewCfg_sigDescB)
		{
			this.LiveViewCfg_AuxEnabled = LiveViewCfg_AuxEnabled;
			this.LiveViewCfg_AuxAddress = LiveViewCfg_AuxAddress;
			this.LiveViewCfg_AuxLength = LiveViewCfg_AuxLength;
			this.LiveViewCfg_sigDescA = LiveViewCfg_sigDescA;
			this.LiveViewCfg_sigDescB = LiveViewCfg_sigDescB;
			LiveViewCfg_ExpertEnable = LiveViewCfg_ExpertEnabled;
			LiveViewCfg_RecInterval_ms = recordInterval_ms;
			threadManager.AddTask(TH_LiveViewSaveConfig, logpath);
		}

		public void ECU_Disconnect()
		{
			AbortThread(false);
			threadManager.AddTask(TH_ECUDisconnect, new object());
		}

		public void EngineSerialWrite(string sn)
		{
			threadManager.AddTask(TH_EngineSerialWrite, sn);
		}

		public void EngineSerialRead()
		{
			baseServiceA.EngineSerialRead();
			baseServiceB.EngineSerialRead();
		}

		public void EngineUptimeReset()
		{
			threadManager.AddTask(TH_EngineUptimeReset, new object());
		}

		private void ProgressStepSecureRaise(string stepname)
		{
			if (this.ev_ProgressStep != null && this.ev_ProgressStep != null)
			{
				this.ev_ProgressStep(this, new ServiceLayerStringEventArg(stepname));
			}
		}

		private void ProgressCloseSecureRaise()
		{
			if (this.ev_ProgressClose != null)
			{
				this.ev_ProgressClose(this, new ServiceLayerBoolEventArg(false));
			}
		}

		public void DatLog_Config_Write()
		{
			threadManager.AddTask(TH_DatLog_Config_Write, new object());
		}

		public void DatLog_Config_Read()
		{
			threadManager.AddTask(TH_DatLog_Config_Read, new object());
		}

		public void RecManFormat()
		{
			threadManager.AddTask(TH_RecManFormat, new object());
		}

		public void RecManFormatScr()
		{
			if (this.ev_ProgressTimerSetup != null)
			{
				this.ev_ProgressTimerSetup(this, new ServiceLayerStringEventArg("Formatting RecMng-Flash ECU A...\nThis takes about 3 minutes for both ECU's.", 200000));
			}
			threadManager.AddTask(TH_RecManFormat, new object());
		}

		public void RTCWrite(string rtc)
		{
			threadManager.AddTask(TH_RTCWrite, rtc);
		}

		public void SecurityDetectAccessRights()
		{
			baseServiceA.SecurityDetectAccessRights(false);
		}

		public static void SecurityEncryptToFile(string filename, MemoryStream stream)
		{
			stream.SetLength(stream.Position);
			stream = cryptedCompression.GZipCompress(stream, bufZipped);
			stream = new MemoryStream(bufEncrypted, 0, cryptedCompression.EncryptStream(stream, ConfigSecurity.Zauberwort, bufEncrypted));
			FileIO.WriteStreamToFile(stream, filename);
		}

		public static Stream SecurityDecryptFile(string file, string zauberwort, ConfigData.e_FileTypes filetype)
		{
			CryptedCompression cryptedCompression = new CryptedCompression();
			currentLogPath = file;
			MemoryStream memoryStream = new MemoryStream();
			Stream stream = new MemoryStream();
			string text = Path.GetExtension(file).ToLower();
			try
			{
				if (text == ".xml")
				{
					stream = new FileStream(file, FileMode.Open);
					if (!EvaluateFileType(stream, filetype))
					{
						stream.Close();
						return null;
					}
					return new FileStream(file, FileMode.Open);
				}
				if (text == ConfigData.WizardLiteFileExtension || text == ConfigData.WizardEncryptedOutput_FileExtension)
				{
					try
					{
						FileStream fileStream = File.OpenRead(file);
						MemoryStream memoryStream2 = new MemoryStream(bufEncrypted, 0, (int)fileStream.Length, true, true);
						fileStream.Read(memoryStream2.GetBuffer(), 0, (int)fileStream.Length);
						memoryStream2.Flush();
						stream = cryptedCompression.DecryptStream(memoryStream2, zauberwort, bufZipped);
						stream.SetLength(stream.Position);
						stream = new MemoryStream(bufUnModified, 0, cryptedCompression.GZipDecompress((MemoryStream)stream, bufUnModified), true, true);
						memoryStream2.Close();
						fileStream.Close();
						if (stream.Position != 0)
						{
							stream.Position = 0L;
						}
						((MemoryStream)stream).WriteTo(memoryStream);
						if (!EvaluateFileType(memoryStream, filetype))
						{
							stream.Close();
							memoryStream.Close();
							return null;
						}
						return stream;
					}
					catch
					{
						MessageBox.Show("Error when decrypting file. EngineLog could not be opened", ConfigData.WizardSwName);
						return null;
					}
				}
				MessageBox.Show("File is not a valid Wizard - file.\r\nExtension must be *.xml or *" + ConfigData.WizardLiteFileExtension + "!", ConfigData.WizardSwName);
				return null;
			}
			catch
			{
				MessageBox.Show("File is not a valid Wizard - file.\r\nExtension must be *.xml or *" + ConfigData.WizardLiteFileExtension + "!", ConfigData.WizardSwName);
				return null;
			}
		}

		public void EEPROM_Backup_SaveXML(Stream str)
		{
			threadManager.AddTask(TH_EEPROM_Backup_SaveXML, str);
		}

		public void EEPROM_Backup_LoadXML(string logpath)
		{
			threadManager.AddTask(TH_EEPROM_Backup_LoadXML, logpath);
		}

		public void EngLogLoadXML(string logpath)
		{
			threadManager.AddTask(TH_EngLogLoadXML, logpath);
		}

		public void EngLogSave(string logpath)
		{
			threadManager.AddTask(TH_EngLogSaveStream, logpath);
		}

		public void ReadEngLogEvRecDatLog(int hours)
		{
			DatLog_Init();
			threadManager.AddTask(TH_ReadEngLogEvRecDatLog, hours);
		}

		private void EngLogTotalEngineTimeUpdate()
		{
			try
			{
				double num = baseServiceA.EcuData.TotalECUEngineControlTime_raw + baseServiceB.EcuData.TotalECUEngineControlTime_raw;
				baseServiceA.EngineTotalEngineTimeUpdate(string.Format("{0:F2}", (float)(num / 3600.0)) + " h ");
				baseServiceB.EngineTotalEngineTimeUpdate(string.Format("{0:F2}", (float)(num / 3600.0)) + " h ");
			}
			catch
			{
				baseServiceA.EngineTotalEngineTimeUpdate("not available");
				baseServiceB.EngineTotalEngineTimeUpdate("not available");
			}
		}

		private bool ECU_TryToConnect()
		{
			int num = ConfigData.ConnectAttempts;
			bool result = false;
			while (num > 0)
			{
				if (baseServiceA.ECUisOnline() && baseServiceB.ECUisOnline())
				{
					if (this.ev_SecurityReEvaluateRights != null)
					{
						this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
					}
					return true;
				}
				if (!baseServiceA.ECUisOnline())
				{
					baseServiceA.CommunicationStart(true);
				}
				if (!baseServiceB.ECUisOnline())
				{
					baseServiceB.CommunicationStart(true);
				}
				num--;
			}
			if (!baseServiceA.ECUisOnline())
			{
				MessageBox.Show("Error when connecting to ECU, ECU_A not connected, please try again.", ConfigData.WizardSwName);
				baseServiceA.CommunicationStop();
				ProgressCloseSecureRaise();
				result = true;
			}
			if (!baseServiceB.ECUisOnline())
			{
				MessageBox.Show("Error when connecting to ECU, ECU_B not connected, please try again.", ConfigData.WizardSwName);
				baseServiceB.CommunicationStop();
				ProgressCloseSecureRaise();
				result = true;
			}
			return result;
		}

		public void GetSessionLogSave(ref List<string> pathNames)
		{
			bool flag = false;
			bool flag2 = false;
			pathNames.Clear();
			int num = string.Compare(sessionLogFilePathAndNameA, sessionLogFilePathAndNameB);
			if (sessionLogFilePathAndNameA.Length > 3)
			{
				flag = true;
			}
			if (sessionLogFilePathAndNameA.Length > 3)
			{
				flag2 = true;
			}
			if (flag)
			{
				if (num == 0)
				{
					flag2 = false;
				}
				pathNames.Add(sessionLogFilePathAndNameA);
			}
			if (flag2)
			{
				pathNames.Add(sessionLogFilePathAndNameB);
			}
		}

		private void SessionLogInit()
		{
			sessionLogFilePathAndNameA = ConfigData.LogRootPath + "\\" + baseServiceA.EcuData.EcuSerialNumber;
			sessionLogFilePathAndNameB = ConfigData.LogRootPath + "\\" + baseServiceB.EcuData.EcuSerialNumber;
			Directory.CreateDirectory(sessionLogFilePathAndNameA);
			Directory.CreateDirectory(sessionLogFilePathAndNameB);
			sessionLogFilePathAndNameA = sessionLogFilePathAndNameA + "\\" + DateTime.UtcNow.ToString("yyyy.MM.dd hh-mm-ss") + ".txt";
			sessionLogFilePathAndNameB = sessionLogFilePathAndNameB + "\\" + DateTime.UtcNow.ToString("yyyy.MM.dd hh-mm-ss") + ".txt";
			if (string.Compare(sessionLogFilePathAndNameA, sessionLogFilePathAndNameB) != 0)
			{
				bool flag = baseServiceA.EcuData.EcuSerialNumber == "not available";
			}
		}

		private void uigrphWin_AbortThread(object sender, EventArgs e)
		{
			if (sender is Xml_Log)
			{
				if (!((Xml_Log)sender).IsClosed())
				{
					if (LiveView_LogPath.Length == 0)
					{
						MessageBox.Show("LiveView: Error when writing record data to file, no filename provided!");
						return;
					}
					((Xml_Log)sender).SaveLiveViewFooter();
					((Xml_Log)sender).EndLog();
					SecurityEncryptToFile(LiveView_LogPath, originalStream);
					LiveView_LogPath = "";
				}
			}
			else if (sender is UIGraphLiveView)
			{
				UIGraphLiveView uIGraphLiveView = (UIGraphLiveView)sender;
				GaphObj gaphObj = GraphServicesList[uIGraphLiveView.myListNr];
				gaphObj.grphType = EGrapphObjType.eNoGraphObjType;
				gaphObj.logPath = null;
				gaphObj.recManA = null;
				gaphObj.recManB = null;
			}
			else if (sender is UIGraphWindow)
			{
				UIGraphWindow uIGraphWindow = (UIGraphWindow)sender;
				GaphObj gaphObj2 = GraphServicesList[uIGraphWindow.UiGraph1.myListNr];
				LiveView liveView = (LiveView)gaphObj2.recManA;
				LiveView liveView2 = (LiveView)gaphObj2.recManB;
				liveView.RecordStop();
				liveView2.RecordStop();
				if (liveView.XmlLog != null)
				{
					lock (liveView.XmlLog)
					{
						if (!liveView.XmlLog.IsClosed())
						{
							liveView.XmlLog.SaveLiveViewFooter();
							liveView.XmlLog.EndLog();
							SecurityEncryptToFile(gaphObj2.logPath, liveView.XmlLog.myStream);
						}
					}
				}
				else if (liveView2.XmlLog != null)
				{
					lock (liveView2.XmlLog)
					{
						if (!liveView2.XmlLog.IsClosed())
						{
							liveView.XmlLog.SaveLiveViewFooter();
							liveView.XmlLog.EndLog();
							SecurityEncryptToFile(gaphObj2.logPath, liveView.XmlLog.myStream);
						}
					}
				}
				uIGraphWindow.Dispose();
				gaphObj2.grphType = EGrapphObjType.eNoGraphObjType;
				gaphObj2.logPath = null;
				gaphObj2.recManA = null;
				gaphObj2.recManB = null;
			}
			GC.Collect(2);
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
		}

		private int SetPosOfInputSign(ref List<int> sigDesc, int sig)
		{
			int result = 172;
			for (int i = 0; i < sigDesc.Count; i++)
			{
				if (sigDesc[i] == sig)
				{
					result = i;
				}
			}
			return result;
		}

		public void LiveViewInit(ref LiveView lvA, ref LiveView lvB)
		{
			lvA.ev_AddConsoleEvent += servicelayer_ev_AddConsole;
			lvA.ev_LiveViewRecordStopped += LiveViewRecordingStoppedHandler;
			lvA.ev_LiveViewRecordError += LiveViewRecordingErrorHandler;
			lvB.ev_AddConsoleEvent += servicelayer_ev_AddConsole;
			lvB.ev_LiveViewRecordStopped += LiveViewRecordingStoppedHandler;
			lvB.ev_LiveViewRecordError += LiveViewRecordingErrorHandler;
		}

		private void LiveViewSetupInternal(ref LiveView lvA, ref LiveView lvB, int recInterval_ms, ref UIGraphWindow uiGrp)
		{
			bool flag = false;
			for (int i = 0; i < baseServiceA.EcuData.LiveViewSignals.Count; i++)
			{
				LogSignalLiveView signal = baseServiceA.EcuData.LiveViewSignals[i];
				lvA.SignalAdd(ref signal);
			}
			for (int i = 0; i < baseServiceB.EcuData.LiveViewSignals.Count; i++)
			{
				LogSignalLiveView signal = baseServiceB.EcuData.LiveViewSignals[i];
				lvB.SignalAdd(ref signal);
			}
			if (baseServiceA.EcuData.LiveViewVirtualSignals != null)
			{
				for (int i = 0; i < baseServiceA.EcuData.LiveViewVirtualSignals.Count; i++)
				{
					ConfigLiveView.LiveViewVirtualSig vSignal = baseServiceA.EcuData.LiveViewVirtualSignals[i];
					lvA.VirtualSigAdd(ref vSignal);
				}
			}
			if (baseServiceB.EcuData.LiveViewVirtualSignals != null)
			{
				for (int i = 0; i < baseServiceB.EcuData.LiveViewVirtualSignals.Count; i++)
				{
					ConfigLiveView.LiveViewVirtualSig vSignal = baseServiceB.EcuData.LiveViewVirtualSignals[i];
					lvB.VirtualSigAdd(ref vSignal);
				}
			}
			uiGrp.UiGraph1.GraphVars = new ArrayList();
			uiGrp.UiGraph1.GraphVars.Capacity = 32;
			uiGrp.UiGraph1.GraphVars_hash = new Hashtable();
			for (int i = 0; i < lvA.listECUVars.Count; i++)
			{
				UIGraphBase.CheckedSigVals item = default(UIGraphBase.CheckedSigVals);
				Var var = lvA.listECUVars[i];
				item.sigName = var.Name;
				item.sigVal = string.Empty;
				item.chkBoxColor = var.LineColor;
				if (!flag && uiGrp.UiGraph1.checkedSigIx.Count == 0)
				{
					item.checkedStatus = true;
					flag = true;
				}
				uiGrp.UiGraph1.checkedSigIx.Add(item);
				uiGrp.UiGraph1.GraphVars.Add(var);
				uiGrp.UiGraph1.GraphVars_hash.Add(var.Titel, var);
			}
			for (int i = 0; i < lvB.listECUVars.Count; i++)
			{
				UIGraphBase.CheckedSigVals item = default(UIGraphBase.CheckedSigVals);
				Var var = lvB.listECUVars[i];
				item.sigName = var.Name;
				item.sigVal = string.Empty;
				item.chkBoxColor = var.LineColor;
				if (!flag && uiGrp.UiGraph1.checkedSigIx.Count == 0)
				{
					item.checkedStatus = true;
					flag = true;
				}
				uiGrp.UiGraph1.checkedSigIx.Add(item);
				uiGrp.UiGraph1.GraphVars.Add(var);
				uiGrp.UiGraph1.GraphVars_hash.Add(var.Titel, var);
			}
			uiGrp.UiGraph1.Addvar(null);
		}

		private void TH_EngLogSave_PayloadOnly(Xml_Log EngineLog)
		{
			try
			{
				object[,] array = new object[8, 14];
				object[,] array2 = new object[8, 14];
				TH_EngineIDSave(EngineLog);
				ProgressStepSecureRaise("Reading statistics ECU A...");
				ConfigData.ECUCONNECTED eCUCONNECTED = ECU_VerifyECUConnected();
				if (eCUCONNECTED == ConfigData.ECUCONNECTED.e_ECU_ALL_CONNECTED || eCUCONNECTED == ConfigData.ECUCONNECTED.e_ECU_A_CONNECTED)
				{
					baseServiceA.Statistics_Read();
				}
				if (eCUCONNECTED == ConfigData.ECUCONNECTED.e_ECU_ALL_CONNECTED || eCUCONNECTED == ConfigData.ECUCONNECTED.e_ECU_B_CONNECTED)
				{
					baseServiceB.Statistics_Read();
				}
				for (int i = 0; i < 8; i++)
				{
					array[i, 8] = ConfigStatistics.TimerTextArray[i];
					array[i, 9] = ConfigStatistics.TimerSignalArray[i];
					array[i, 10] = ConfigStatistics.TimerUnitArray[i];
					array[i, 11] = ConfigStatistics.BereichsArray[i, 0];
					array[i, 12] = ConfigStatistics.BereichsArray[i, 8];
					array[i, 13] = ConfigStatistics.BereichsArray.GetLength(1) - 1;
					array2[i, 8] = ConfigStatistics.TimerTextArray[i];
					array2[i, 9] = ConfigStatistics.TimerSignalArray[i];
					array2[i, 10] = ConfigStatistics.TimerUnitArray[i];
					array2[i, 11] = ConfigStatistics.BereichsArray[i, 0];
					array2[i, 12] = ConfigStatistics.BereichsArray[i, 8];
					array2[i, 13] = ConfigStatistics.BereichsArray.GetLength(1) - 1;
					for (int j = 0; j < 8; j++)
					{
						array[i, j] = baseServiceA.EcuData.Statistics[i, j];
						array2[i, j] = baseServiceB.EcuData.Statistics[i, j];
					}
				}
				EngineLog.WriteStartElement("STATISTICS", "Section Statistics");
				EngineLog.SaveStatistics(array, "A");
				ProgressStepSecureRaise("Reading statistics ECU B...");
				EngineLog.SaveStatistics(array2, "B");
				ProgressStepSecureRaise("Reading FCM ECU A...");
				EngineLog.WriteEndElement();
				EngineLog.WriteStartElement("FAULT_CODE_MEMORY", "Section Fault Code Memory");
				if (eCUCONNECTED == ConfigData.ECUCONNECTED.e_ECU_ALL_CONNECTED || eCUCONNECTED == ConfigData.ECUCONNECTED.e_ECU_A_CONNECTED)
				{
					EngineLog.SaveDTC(baseServiceA.DTCListRead(), "A");
				}
				ProgressStepSecureRaise("Reading FCM ECU B...");
				if (eCUCONNECTED == ConfigData.ECUCONNECTED.e_ECU_ALL_CONNECTED || eCUCONNECTED == ConfigData.ECUCONNECTED.e_ECU_B_CONNECTED)
				{
					EngineLog.SaveDTC(baseServiceB.DTCListRead(), "B");
				}
				EngineLog.WriteEndElement();
				ProgressStepSecureRaise("");
				ProgressStepSecureRaise("Reading IQA ECU A...");
				if (eCUCONNECTED == ConfigData.ECUCONNECTED.e_ECU_ALL_CONNECTED || eCUCONNECTED == ConfigData.ECUCONNECTED.e_ECU_A_CONNECTED)
				{
					baseServiceA.IQAReadCyl(72);
				}
				ProgressStepSecureRaise("Reading IQA ECU B...");
				if (eCUCONNECTED == ConfigData.ECUCONNECTED.e_ECU_ALL_CONNECTED || eCUCONNECTED == ConfigData.ECUCONNECTED.e_ECU_B_CONNECTED)
				{
					baseServiceB.IQAReadCyl(72);
				}
				EngineLog.IQACode(baseServiceA.EcuData.IQACylRead, baseServiceB.EcuData.IQACylRead);
			}
			catch
			{
			}
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
		}

		private void TH_EngLogSaveStream(object file)
		{
			string text = (string)file;
			ProgressStepSecureRaise("Connecting...");
			Xml_Log xml_Log = new Xml_Log();
			originalStream = new MemoryStream();
			ProgressStepSecureRaise("");
			try
			{
				xml_Log.CreateLogStream(originalStream, "ENGINE_LOG", false);
				ProgressStepSecureRaise("Creating file-header...");
				xml_Log.FileID(Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(text)) + ".xml");
				ProgressStepSecureRaise("");
				xml_Log.SwID(ConfigData.WizardSwName, ConfigData.WizardSwVersion, ConfigData.WizardManufacturer, ConfigData.EcuVersionsStrings[(uint)ConfigData.ecuSwVersion]);
				ProgressStepSecureRaise("");
				xml_Log.UserID();
				ProgressStepSecureRaise("Reading engine-info...");
				TH_EngLogSave_PayloadOnly(xml_Log);
				xml_Log.EndLog();
				ProgressStepSecureRaise("Writing file...");
				SecurityEncryptToFile(text, originalStream);
				ProgressCloseSecureRaise();
				if (this.ev_ProcessFinished != null)
				{
					this.ev_ProcessFinished(this, new ServiceLayerProcessTypeEventArg(ConfigData.e_WizardProcesses.ENGINE_LOG_SAVE));
				}
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				if (originalStream != null)
				{
					originalStream.Close();
				}
			}
			catch (Exception ex)
			{
				xml_Log.Close();
				originalStream.Close();
				ProgressCloseSecureRaise();
				if (this.ev_ProcessError != null)
				{
					this.ev_ProcessError(this, new ServiceLayerProcessTypeEventArg(ConfigData.e_WizardProcesses.ENGINE_LOG_SAVE));
				}
				MessageBox.Show(string.Concat("An error ocurred during read-process, engine-log-file might be corrupt.\r\nMessage:\n", ex.Message, "\r\nTarget:\n", ex.TargetSite, "\r\nSource:\n", ex.Source, ConfigData.WizardSwName), ConfigData.WizardSwName);
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
			}
		}

		private void TH_ECUConnect(object state)
		{
			if (!ECU_TryToConnect())
			{
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				return;
			}
			EngLogTotalEngineTimeUpdate();
			SessionLogInit();
			if (this.ev_AddConsoleEvent != null)
			{
				this.ev_AddConsoleEvent("LOG-File", Color.Black, null);
			}
			if (this.ev_SessionLogSaveCautionLamp != null)
			{
				this.ev_SessionLogSaveCautionLamp(this, null);
			}
			if (this.ev_SessionLogTriggerSave != null)
			{
				this.ev_SessionLogTriggerSave(this, null);
			}
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
			if (ConfigData.ecuSwVersion == ConfigData.ECUSWVERSION.e_ECU_ERR_VERSION)
			{
				MessageBox.Show(string.Format("This Wizard version does not support ECUs SW-version  !\nPlease update your Wizard version, or contact Austro Engine after sales."), "Critical Warning !");
			}
		}

		private void TH_ECUConnectTmp(object state)
		{
			if (!ECU_TryToConnect())
			{
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
			}
			else if (this.ev_AddConsoleEvent != null)
			{
				this.ev_AddConsoleEvent("LOG-File", Color.Black, null);
			}
		}

		private void TH_ShutdownServices(object state)
		{
			TH_ECUDisconnect(state);
			baseServiceA.USBDongleClose();
			AbortThread(true);
		}

		public void TH_ECUDisconnect(object state)
		{
			try
			{
				if (BaseServiceA.ECUisOnline())
				{
					baseServiceA.CommunicationStop();
				}
				if (BaseServiceB.ECUisOnline())
				{
					baseServiceB.CommunicationStop();
				}
			}
			catch
			{
			}
			if (this.ev_SessionLogTriggerSave != null)
			{
				this.ev_SessionLogTriggerSave(this, null);
			}
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
			baseServiceA.EcuAccess.ECUReceiveConnect(false);
		}

		private void copyDTC(DTC a, DTC d)
		{
			a.cautionlampText = d.cautionlampText;
			a.displaytext = d.displaytext;
			a.ErrTyp_first = d.ErrTyp_first;
			a.ErrTyp_firstText = d.ErrTyp_firstText;
			a.ErrTyp_last = d.ErrTyp_last;
			a.ErrTyp_lastText = d.ErrTyp_lastText;
			a.freq = d.freq;
			a.id = d.id;
			a.signal = d.signal;
			a.statusText = d.statusText;
			for (int i = 0; i < d.vals.Length; i++)
			{
				a.vals[i] = new DTC.Env(d.vals[i]);
			}
		}

		private void TH_DTCRead(object state)
		{
			try
			{
				BaseServiceA.EcuData.DTCArray = new DTC[0];
				BaseServiceB.EcuData.DTCArray = new DTC[0];
				baseServiceA.DTCListRead();
				baseServiceB.DTCListRead();
			}
			catch
			{
			}
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
			if (this.ev_DTCDataRefreshed != null)
			{
				this.ev_DTCDataRefreshed(this, null);
			}
		}

		private void TH_StatisticsRead(object state)
		{
			try
			{
				baseServiceA.Statistics_Read();
				baseServiceB.Statistics_Read();
			}
			catch
			{
			}
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
			if (this.ev_StatisticsUpdated != null)
			{
				this.ev_StatisticsUpdated(this, null);
			}
		}

		private void TH_DTCClear(object DTC_read_precheck)
		{
			if (!ECU_VerifyBothConnected())
			{
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				return;
			}
			if ((bool)DTC_read_precheck && (!baseServiceA.EcuData.DTCReadOut || !baseServiceB.EcuData.DTCReadOut))
			{
				MessageBox.Show("Please read fault code memory first", ConfigData.WizardSwName);
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				if (this.ev_ProcessError != null)
				{
					this.ev_ProcessError(this, new ServiceLayerProcessTypeEventArg(ConfigData.e_WizardProcesses.DTC_CLEAR));
				}
				return;
			}
			baseServiceA.DTCClear();
			baseServiceB.DTCClear();
			if (this.ev_SessionLogSaveCautionLamp != null)
			{
				this.ev_SessionLogSaveCautionLamp(this, null);
			}
			if (this.ev_SessionLogTriggerSave != null)
			{
				this.ev_SessionLogTriggerSave(this, null);
			}
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
			if (this.ev_ProcessFinished != null)
			{
				this.ev_ProcessFinished(this, new ServiceLayerProcessTypeEventArg(ConfigData.e_WizardProcesses.DTC_CLEAR));
			}
		}

		private void TH_EngLogLoadXML(object logpath)
		{
			Stream stream = SecurityDecryptFile((string)logpath, ConfigSecurity.Zauberwort, ConfigData.e_FileTypes.ENGINE_LOG);
			Xml_Log xml_Log = new Xml_Log();
			if (stream == null)
			{
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				if (this.ev_ProgressClose != null)
				{
					this.ev_ProgressClose(this, new ServiceLayerBoolEventArg(false));
				}
				return;
			}
			stream.Position = 0L;
			XmlReader xmlReader = XmlReader.Create(stream);
			try
			{
				stream.Position = 0L;
				baseServiceA.EngineInfoUpdateXML(stream);
				string[] array = baseServiceA.EcuData.EcuSwVersion.Split('_');
				if (array.Length > 3)
				{
					string[] array2 = array[3].Split(' ');
					if (array2[0].Length > 3)
					{
						ConfigData.ecuSwVerDTC = ConfigData.ECUSWVERDTC.eECUSWVERDTCMore23;
					}
					else if (int.Parse(array2[0]) >= 23)
					{
						ConfigData.ecuSwVerDTC = ConfigData.ECUSWVERDTC.eECUSWVERDTCMore23;
					}
					else
					{
						ConfigData.ecuSwVerDTC = ConfigData.ECUSWVERDTC.eECUSWVERDTCLess23;
					}
				}
				baseServiceB.EngineInfoUpdateXML(stream);
				stream.Position = 0L;
				xmlReader = XmlReader.Create(stream);
				List<DTC> dtcListA = new List<DTC>();
				List<DTC> dtcListB = new List<DTC>();
				xml_Log.DTCLoad(xmlReader, ref dtcListA, ref dtcListB);
				baseServiceA.EcuData.DTCArray = dtcListA.ToArray();
				baseServiceB.EcuData.DTCArray = dtcListB.ToArray();
				stream.Position = 0L;
				xmlReader = XmlReader.Create(stream);
				string[,] statsAndHeaderA = new string[8, 14];
				string[,] statsAndHeaderB = new string[8, 14];
				xml_Log.ReadStatistics(xmlReader, ref statsAndHeaderA, ref statsAndHeaderB);
				int[,] array3 = new int[8, 8];
				int[,] array4 = new int[8, 8];
				for (int i = 0; i < 8; i++)
				{
					ConfigStatistics.TimerTextArray[i] = statsAndHeaderA[i, 8];
					ConfigStatistics.TimerSignalArray[i] = statsAndHeaderA[i, 9];
					ConfigStatistics.TimerUnitArray[i] = statsAndHeaderA[i, 10];
					ConfigStatistics.BereichsArray[i, 0] = statsAndHeaderA[i, 11];
					ConfigStatistics.BereichsArray[i, 8] = statsAndHeaderA[i, 12];
					for (int j = 0; j < 8; j++)
					{
						array3[i, j] = int.Parse(statsAndHeaderA[i, j]);
						array4[i, j] = int.Parse(statsAndHeaderB[i, j]);
					}
				}
				baseServiceA.EcuData.Statistics = array3;
				baseServiceB.EcuData.Statistics = array4;
				if (this.ev_DTCDataRefreshed != null)
				{
					this.ev_DTCDataRefreshed(this, null);
				}
				if (this.ev_StatisticsUpdated != null)
				{
					this.ev_StatisticsUpdated(this, null);
				}
				if (this.ev_EngineLogUpdated != null)
				{
					this.ev_EngineLogUpdated(this, null);
				}
				stream.Position = 0L;
				xmlReader = XmlReader.Create(stream);
				string[] IQACylValA = new string[4] { " ", " ", " ", " " };
				string[] IQACylValB = new string[4] { " ", " ", " ", " " };
				xml_Log.ReadIQA(xmlReader, ref IQACylValA, ref IQACylValB);
				baseServiceA.EcuData.IQACylWrite[0] = IQACylValA[0];
				baseServiceA.EcuData.IQACylWrite[1] = IQACylValA[1];
				baseServiceA.EcuData.IQACylWrite[2] = IQACylValA[2];
				baseServiceA.EcuData.IQACylWrite[3] = IQACylValA[3];
				baseServiceB.EcuData.IQACylWrite[0] = IQACylValB[0];
				baseServiceB.EcuData.IQACylWrite[1] = IQACylValB[1];
				baseServiceB.EcuData.IQACylWrite[2] = IQACylValB[2];
				baseServiceB.EcuData.IQACylWrite[3] = IQACylValB[3];
				if (this.ev_IQADataCylWriteUpdated != null)
				{
					this.ev_IQADataCylWriteUpdated(this, null);
				}
				stream.Close();
				xmlReader.Close();
			}
			catch
			{
				stream.Close();
				xmlReader.Close();
				MessageBox.Show("Error during XML import, file may be incomplete or corrupt", ConfigData.WizardSwName);
			}
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
		}

		private void TH_EngineSerialWrite(object sn)
		{
			try
			{
				byte[] array = new byte[16];
				string text = (string)sn;
				int length = ((string)sn).Length;
				if (length < 10)
				{
					MessageBox.Show("Invalid length of serial number", ConfigData.WizardSwName);
					return;
				}
				if (!ECU_VerifyBothConnected())
				{
					if (this.ev_SecurityReEvaluateRights != null)
					{
						this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
					}
					return;
				}
				for (int i = 0; i < 16; i++)
				{
					if (i < length)
					{
						array[i] = (byte)text[i];
					}
					else
					{
						array[i] = 0;
					}
				}
				baseServiceA.EngineSerialWrite(array);
				baseServiceB.EngineSerialWrite(array);
				Thread.Sleep(1000);
				baseServiceA.EngineInfoUpdate();
				baseServiceB.EngineInfoUpdate();
			}
			catch
			{
			}
			if (this.ev_SessionLogTriggerSave != null)
			{
				this.ev_SessionLogTriggerSave(this, null);
			}
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
		}

		private void TH_RTCWrite(object rtcArray)
		{
			if (!ECU_VerifyBothConnected())
			{
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				return;
			}
			byte[] array = new byte[6];
			string[] array2 = new string[6]
			{
				((string)rtcArray).Substring(0, 2),
				((string)rtcArray).Substring(2, 2),
				((string)rtcArray).Substring(4, 2),
				((string)rtcArray).Substring(6, 2),
				((string)rtcArray).Substring(8, 2),
				((string)rtcArray).Substring(10, 2)
			};
			DateTime dateTime = default(DateTime);
			try
			{
				dateTime = new DateTime(Convert.ToInt32(array2[2]), Convert.ToInt32(array2[1]), Convert.ToInt32(array2[0]), Convert.ToInt32(array2[3]), Convert.ToInt32(array2[4]), Convert.ToInt32(array2[5]));
			}
			catch
			{
				MessageBox.Show("Please enter a valid date!", ConfigData.WizardSwName);
				if (this.ev_SessionLogTriggerSave != null)
				{
					this.ev_SessionLogTriggerSave(this, null);
				}
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				return;
			}
			array[0] = (byte)Convert.ToInt32(dateTime.ToString("yy"), 16);
			array[1] = (byte)Convert.ToInt32(dateTime.ToString("MM"), 16);
			array[2] = (byte)Convert.ToInt32(dateTime.ToString("dd"), 16);
			array[3] = (byte)Convert.ToInt32(dateTime.ToString("HH"), 16);
			array[4] = (byte)Convert.ToInt32(dateTime.ToString("mm"), 16);
			array[5] = (byte)Convert.ToInt32(dateTime.ToString("ss"), 16);
			baseServiceA.RTCWrite(array);
			baseServiceB.RTCWrite(array);
			Thread.Sleep(1000);
			baseServiceA.RTCRead();
			baseServiceB.RTCRead();
			if (this.ev_SessionLogTriggerSave != null)
			{
				this.ev_SessionLogTriggerSave(this, null);
			}
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
		}

		private void TH_IQA_Init_1(object state)
		{
			if (!ECU_VerifyBothConnected())
			{
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				return;
			}
			baseServiceA.IQAInitialize1(true);
			baseServiceB.IQAInitialize1(true);
			if (baseServiceA.EcuData.IQAInitStep1Done && baseServiceB.EcuData.IQAInitStep1Done)
			{
				MessageBox.Show("Disconnect and perform afterrun,\nthen reconnect and continue with Initialize IQA Step 2", ConfigData.WizardSwName);
			}
			else
			{
				MessageBox.Show("An error has occurred\nInitialize IQA was not successful", ConfigData.WizardSwName);
			}
			if (this.ev_SessionLogTriggerSave != null)
			{
				this.ev_SessionLogTriggerSave(this, null);
			}
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
		}

		private void TH_IQA_Init_2(object state)
		{
			if (!ECU_VerifyBothConnected())
			{
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				return;
			}
			baseServiceA.IQAInitialize2();
			baseServiceB.IQAInitialize2();
			if (baseServiceA.EcuData.IQAInitStep2Done && baseServiceA.EcuData.IQAInitStep2Done)
			{
				baseServiceA.IQAReadCyl(72);
				baseServiceB.IQAReadCyl(72);
				if (this.ev_IQADataCylReadUpdated != null)
				{
					this.ev_IQADataCylReadUpdated(this, null);
				}
			}
			else
			{
				MessageBox.Show("An error has occurred\nInitialize IQA was not successful", ConfigData.WizardSwName);
			}
			if (this.ev_SessionLogTriggerSave != null)
			{
				this.ev_SessionLogTriggerSave(this, null);
			}
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
		}

		public void IQA_Init2Script()
		{
			if (ECU_VerifyBothConnected())
			{
				baseServiceA.IQAInitialize2();
				baseServiceB.IQAInitialize2();
			}
		}

		private void TH_IQALoadXML(object logpath)
		{
			Xml_Log xml_Log = new Xml_Log();
			Stream stream = SecurityDecryptFile((string)logpath, ConfigSecurity.Zauberwort, ConfigData.e_FileTypes.IQA);
			if (stream == null)
			{
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				if (this.ev_ProgressClose != null)
				{
					this.ev_ProgressClose(this, new ServiceLayerBoolEventArg(false));
				}
				return;
			}
			stream.Position = 0L;
			string[] array = xml_Log.ReadIQA(stream);
			if (array[0] == array[4] && array[1] == array[5] && array[2] == array[6] && array[3] == array[7])
			{
				baseServiceA.EcuData.IQACylWrite = new string[4];
				baseServiceB.EcuData.IQACylWrite = new string[4];
				baseServiceA.EcuData.IQACylWrite[0] = array[0];
				baseServiceA.EcuData.IQACylWrite[1] = array[1];
				baseServiceA.EcuData.IQACylWrite[2] = array[2];
				baseServiceA.EcuData.IQACylWrite[3] = array[3];
				baseServiceB.EcuData.IQACylWrite[0] = array[0];
				baseServiceB.EcuData.IQACylWrite[1] = array[1];
				baseServiceB.EcuData.IQACylWrite[2] = array[2];
				baseServiceB.EcuData.IQACylWrite[3] = array[3];
				if (this.ev_IQADataCylWriteUpdated != null)
				{
					this.ev_IQADataCylWriteUpdated(this, null);
				}
			}
			else
			{
				MessageBox.Show("Mismatch between ECU A and ECU B IQA-codes\nfile corrupt", ConfigData.WizardSwName);
			}
			if (this.ev_SessionLogTriggerSave != null)
			{
				this.ev_SessionLogTriggerSave(this, null);
			}
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
		}

		private void TH_IQACylRead(object cylCode)
		{
			if (!ECU_VerifyBothConnected())
			{
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				return;
			}
			BaseServiceA.IQAReadCyl((byte)cylCode);
			BaseServiceB.IQAReadCyl((byte)cylCode);
			if (this.ev_IQADataCylReadUpdated != null)
			{
				this.ev_IQADataCylReadUpdated(this, null);
			}
			if (this.ev_SessionLogTriggerSave != null)
			{
				this.ev_SessionLogTriggerSave(this, null);
			}
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
		}

		private void TH_IQACylWrite(object cylstrs)
		{
			if (!ECU_VerifyBothConnected())
			{
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				return;
			}
			List<byte[]> list;
			try
			{
				list = (List<byte[]>)cylstrs;
			}
			catch
			{
				MessageBox.Show("Internal error:\r\nThreadIQACylWrite: parameter has wrong type!", ConfigData.WizardSwName);
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				return;
			}
			ConfigData.e_IQACylinder e_IQACylinder = ConfigData.e_IQACylinder.one;
			while ((int)e_IQACylinder < 4)
			{
				if (list[(int)e_IQACylinder] != null)
				{
					if (this.ev_AddConsoleEvent != null)
					{
						this.ev_AddConsoleEvent("Write IQA code for Cylinder " + (int)(e_IQACylinder + 1) + " (SID 0x" + string.Format("{0:X2}", ConfigKWP.SendList(ConfigKWP.e_kwpServices.IQA_WriteCylinder)[0]) + ")", Color.Black, "ECU A:");
					}
					baseServiceA.IQAWriteCyl(ConfigData.GetIQACylCode(e_IQACylinder), list[(int)e_IQACylinder]);
					if (this.ev_AddConsoleEvent != null)
					{
						this.ev_AddConsoleEvent("Write IQA code for Cylinder " + (int)(e_IQACylinder + 1) + " (SID 0x" + string.Format("{0:X2}", ConfigKWP.SendList(ConfigKWP.e_kwpServices.IQA_WriteCylinder)[0]) + ")", Color.Black, "ECU B:");
					}
					baseServiceB.IQAWriteCyl(ConfigData.GetIQACylCode(e_IQACylinder), list[(int)e_IQACylinder]);
					Thread.Sleep(50);
				}
				e_IQACylinder++;
			}
			BaseServiceA.IQAReadCyl(ConfigData.GetIQACylCode(ConfigData.e_IQACylinder.ALL));
			BaseServiceB.IQAReadCyl(ConfigData.GetIQACylCode(ConfigData.e_IQACylinder.ALL));
			if (this.ev_IQADataCylReadUpdated != null)
			{
				this.ev_IQADataCylReadUpdated(this, null);
			}
			if (this.ev_SessionLogTriggerSave != null)
			{
				this.ev_SessionLogTriggerSave(this, null);
			}
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
		}

		private void TH_IQASaveXML(object logpath)
		{
			Xml_Log xml_Log = new Xml_Log();
			bool flag = false;
			if (((string)logpath).Contains("IQA_StorageData"))
			{
				flag = true;
			}
			originalStream = new MemoryStream();
			try
			{
				if (flag)
				{
					xml_Log.CreateLogStream(originalStream, "IQA_STORAGE_FILE", false);
				}
				else
				{
					xml_Log.CreateLogStream(originalStream, "IQA_FILE", false);
				}
				xml_Log.FileID(Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension((string)logpath)) + ".xml");
				xml_Log.SwID(ConfigData.WizardSwName, ConfigData.WizardSwVersion, ConfigData.WizardManufacturer, ConfigData.EcuVersionsStrings[(uint)ConfigData.ecuSwVersion]);
				xml_Log.UserID();
				TH_EngineIDSave(xml_Log);
				if (flag)
				{
					xml_Log.IQAScannedCode(IQA_CylA_ReadText);
				}
				else
				{
					xml_Log.IQACode(IQA_CylA_ReadText, IQA_CylB_ReadText);
				}
				xml_Log.EndLog();
				SecurityEncryptToFile((string)logpath, originalStream);
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
			}
			catch (Exception ex)
			{
				xml_Log.Close();
				MessageBox.Show(ex.Message, ConfigData.WizardSwName);
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
			}
		}

		private void TH_EngineIDSave(Xml_Log xmllog)
		{
			if (ECU_VerifyECUConnected() == ConfigData.ECUCONNECTED.e_ECU_NOT_CONNECTED)
			{
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				return;
			}
			if (baseServiceA.ECUSideEnable && baseServiceB.ECUSideEnable)
			{
				baseServiceA.EngineInfoUpdate();
				baseServiceB.EngineInfoUpdate();
				EngLogTotalEngineTimeUpdate();
			}
			xmllog.SaveEngineID(baseServiceA.EcuData, baseServiceB.EcuData);
		}

		private void TH_StatisticsReset(object state)
		{
			if (!ECU_VerifyBothConnected())
			{
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				return;
			}
			baseServiceA.Statistics_Reset();
			baseServiceB.Statistics_Reset();
			if (this.ev_SessionLogTriggerSave != null)
			{
				this.ev_SessionLogTriggerSave(this, null);
			}
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
		}

		private void TH_DatLog_Config_Write(object state)
		{
			if (!ECU_VerifyBothConnected())
			{
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				return;
			}
			baseServiceA.RecManDatLogConfig_Write();
			baseServiceB.RecManDatLogConfig_Write();
			if (this.ev_SessionLogTriggerSave != null)
			{
				this.ev_SessionLogTriggerSave(this, null);
			}
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
		}

		private void TH_DatLog_Config_Read(object state)
		{
			if (!ECU_VerifyBothConnected())
			{
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				return;
			}
			baseServiceA.RecManDatLogConfig_Read();
			baseServiceB.RecManDatLogConfig_Read();
			if (this.ev_SessionLogTriggerSave != null)
			{
				this.ev_SessionLogTriggerSave(this, null);
			}
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
		}

		private void TH_EngineUptimeReset(object state)
		{
			if (!ECU_VerifyBothConnected())
			{
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				return;
			}
			baseServiceA.EngineUptime_Reset();
			Thread.Sleep(1000);
			baseServiceA.EngineInfoUpdate();
			baseServiceB.EngineUptime_Reset();
			Thread.Sleep(1000);
			baseServiceB.EngineInfoUpdate();
			if (this.ev_SessionLogTriggerSave != null)
			{
				this.ev_SessionLogTriggerSave(this, null);
			}
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
		}

		private bool testECUSWRev_WizVer(ref string ecuSWRevStr, ref string ecuSWVer)
		{
			bool result = true;
			string empty = string.Empty;
			string[] array = ecuSWRevStr.Split('_');
			string[] array2 = ecuSWVer.Split('_');
			if (array[2].Length < 3)
			{
				string text = array[2].Split('.')[0];
				if (array[2] != array2[3])
				{
					result = false;
				}
			}
			else if (array[2] != array2[3])
			{
				result = false;
			}
			return result;
		}

		private void TH_LiveViewLoadXML(object grnr)
		{
			try
			{
				GaphObj gaphObj = GraphServicesList[(int)grnr];
				UIGraphWindow uiGrp = (UIGraphWindow)gaphObj.uiGraph;
				LiveView lvA = new LiveView(baseServiceA);
				LiveView lvB = new LiveView(baseServiceB);
				int num = 100;
				DateTime result = default(DateTime);
				baseServiceA.EcuData.LiveViewSignals.Clear();
				List<List<float>> list = new List<List<float>>();
				baseServiceB.EcuData.LiveViewSignals.Clear();
				List<List<float>> list2 = new List<List<float>>();
				Xml_Log xml_Log = new Xml_Log();
				xml_Log.ev_ProgressClose += servicelayer_ev_ProgressClose;
				xml_Log.ev_ProgressStep += servicelayer_ev_ProgressStep;
				Stream stream = SecurityDecryptFile(gaphObj.logPath, ConfigSecurity.Zauberwort, ConfigData.e_FileTypes.LIVEVIEW);
				if (stream == null)
				{
					if (this.ev_SecurityReEvaluateRights != null)
					{
						this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
					}
					servicelayer_ev_ProgressClose(this, new ServiceLayerBoolEventArg(false));
					return;
				}
				stream.Position = 0L;
				XmlReader reader = XmlReader.Create(stream);
				dataLogInfo = new Xml_Log.CXmlFileLogInfo();
				xml_Log.ReadXmlFileLogInfo(reader, ref dataLogInfo);
				if (dataLogInfo.ecuSWRevisionA != null && !testECUSWRev_WizVer(ref dataLogInfo.ecuSWRevisionA, ref dataLogInfo.ecuSWVer))
				{
					MessageBox.Show(string.Format("This file was recorded with outdated Wizard {0} !\nSome values are wrong !", dataLogInfo.swVer), "Critical Warning !");
				}
				uiGrp.UiGraph1.fileInfo = new FileInfoHnd();
				uiGrp.UiGraph1.fileInfo.SetFileInfoStrm(ref dataLogInfo, uiGrp.Location);
				stream.Position = 0L;
				XmlReader xmlReader = XmlReader.Create(stream);
				if (!DateTime.TryParse(dataLogInfo.fileCreation, out result))
				{
					result = xml_Log.ReadFileTimeStamp(xmlReader);
				}
				xmlReader.ReadToFollowing("RECORDDATA");
				XmlReader xmlReader2 = xmlReader.ReadSubtree();
				num = xml_Log.ReadLiveViewRecordInterval_ms(xmlReader2, "A");
				if (num <= 0)
				{
					num = 100;
				}
				baseServiceA.EcuData.LiveViewSignals = xml_Log.ReadLiveViewSignalDefs(xmlReader2, "A");
				list = xml_Log.ReadLiveViewSamples(xmlReader2, "A");
				stream.Position = 0L;
				XmlReader xmlReader3 = XmlReader.Create(stream);
				xmlReader3.ReadToFollowing("RECORDDATA");
				XmlReader xmlReader4 = xmlReader3.ReadSubtree();
				baseServiceB.EcuData.LiveViewSignals = xml_Log.ReadLiveViewSignalDefs(xmlReader4, "B");
				list2 = xml_Log.ReadLiveViewSamples(xmlReader4, "B");
				if (stream != null)
				{
					stream.Close();
				}
				if (xmlReader2 != null)
				{
					xmlReader2.Close();
				}
				if (xmlReader4 != null)
				{
					xmlReader4.Close();
				}
				if (xmlReader != null)
				{
					xmlReader.Close();
				}
				if (xmlReader3 != null)
				{
					xmlReader3.Close();
				}
				LiveViewSetupInternal(ref lvA, ref lvB, num, ref uiGrp);
				lvA.FileLoadXML(ref list, result, ref uiGrp);
				lvB.FileLoadXML(ref list2, result, ref uiGrp);
				uiGrp.UiGraph1.listViewCurrentValueEnabled(false);
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
			}
			catch (Exception)
			{
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				MessageBox.Show("Could not read LiveView samples!\nFile is corrupt", ConfigData.WizardSwName);
			}
		}

		private void TH_LiveViewLoadConfig(object logpath)
		{
			Xml_Log xml_Log = new Xml_Log();
			Stream stream = SecurityDecryptFile((string)logpath, ConfigSecurity.Zauberwort, ConfigData.e_FileTypes.LIVEVIEW_CFG);
			if (stream == null)
			{
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				if (this.ev_ProgressClose != null)
				{
					this.ev_ProgressClose(this, new ServiceLayerBoolEventArg(false));
				}
				return;
			}
			stream.Position = 0L;
			bool flag = false;
			string text = "";
			int auxLength = 0;
			try
			{
				List<string> list = new List<string>();
				List<string> list2 = new List<string>();
				List<string> list3 = new List<string>();
				List<string> list4 = new List<string>();
				XmlReader xmlReader = XmlReader.Create(stream);
				object[] array = xml_Log.ReadLiveViewConfig(xmlReader, ConfigData.e_ECUID.A);
				LiveViewCfg_RecInterval_ms = (int)array[0];
				list = (List<string>)array[1];
				LiveViewCfg_ExpertEnable = (bool)array[3];
				stream.Position = 0L;
				XmlReader xmlReader2 = XmlReader.Create(stream);
				object[] array2 = xml_Log.ReadLiveViewConfig(xmlReader2, ConfigData.e_ECUID.B);
				list2 = (List<string>)array2[1];
				foreach (string item in list)
				{
					LogSignalLiveView liveViewSignal_ByName = ConfigLiveView.GetLiveViewSignal_ByName(item, ConfigData.e_ECUID.A);
					list3.Add(liveViewSignal_ByName.description);
				}
				foreach (string item2 in list2)
				{
					LogSignalLiveView liveViewSignal_ByName = ConfigLiveView.GetLiveViewSignal_ByName(item2, ConfigData.e_ECUID.B);
					list4.Add(liveViewSignal_ByName.description);
				}
				if (array[2] != null)
				{
					LogSignalLiveView logSignalLiveView = (LogSignalLiveView)array[2];
					text = "";
					foreach (byte item3 in logSignalLiveView.Address)
					{
						text += string.Format("{0:X2}", item3);
					}
					flag = true;
					auxLength = logSignalLiveView.MemSize;
				}
				else
				{
					flag = false;
				}
				if (array2[2] != null)
				{
					LogSignalLiveView logSignalLiveView2 = (LogSignalLiveView)array2[2];
					text = "";
					foreach (byte item4 in logSignalLiveView2.Address)
					{
						text += string.Format("{0:X2}", item4);
					}
					flag = true;
					auxLength = logSignalLiveView2.MemSize;
				}
				else
				{
					flag = false;
				}
				if (this.ev_LiveViewConfigLoaded != null)
				{
					this.ev_LiveViewConfigLoaded(list3, list4, flag, text, auxLength, LiveViewCfg_ExpertEnable, LiveViewCfg_RecInterval_ms);
				}
				xmlReader.Close();
				xmlReader2.Close();
				xml_Log.Close();
			}
			catch (Exception ex)
			{
				xml_Log.Close();
				MessageBox.Show("Error when loading configuration set:\r\nInternal:\r\n" + ex.Message, ConfigData.WizardSwName);
			}
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
		}

		private void TH_LiveViewSaveConfig(object logpath)
		{
			Xml_Log xml_Log = new Xml_Log();
			originalStream = new MemoryStream();
			try
			{
				LogSignalLiveView liveViewSignal_ByName = ConfigLiveView.GetLiveViewSignal_ByName("Aux_signal", ConfigData.e_ECUID.A);
				List<string> list = new List<string>();
				List<string> list2 = new List<string>();
				xml_Log.CreateLogStream(originalStream, "LIVEVIEW_CONFIG", false);
				ProgressStepSecureRaise("");
				xml_Log.FileID(Path.GetFileName((string)logpath));
				ProgressStepSecureRaise("");
				xml_Log.SwID(ConfigData.WizardSwName, ConfigData.WizardSwVersion, ConfigData.WizardManufacturer, ConfigData.EcuVersionsStrings[(uint)ConfigData.ecuSwVersion]);
				ProgressStepSecureRaise("");
				xml_Log.UserID();
				ProgressStepSecureRaise("");
				if (LiveViewCfg_AuxEnabled)
				{
					liveViewSignal_ByName.ConfigureAuxSignal(LiveViewCfg_AuxAddress, LiveViewCfg_AuxLength);
				}
				foreach (string item in LiveViewCfg_sigDescA)
				{
					list.Add(ConfigLiveView.GetLiveViewSignal_ByDesc(item, ConfigData.e_ECUID.A).Ecu_Message);
				}
				foreach (string item2 in LiveViewCfg_sigDescB)
				{
					list2.Add(ConfigLiveView.GetLiveViewSignal_ByDesc(item2, ConfigData.e_ECUID.B).Ecu_Message);
				}
				if (LiveViewCfg_AuxEnabled)
				{
					xml_Log.SaveLiveViewConfig(list, LiveViewCfg_RecInterval_ms, liveViewSignal_ByName, LiveViewCfg_ExpertEnable, "A");
					ProgressStepSecureRaise("");
					xml_Log.SaveLiveViewConfig(list2, LiveViewCfg_RecInterval_ms, liveViewSignal_ByName, LiveViewCfg_ExpertEnable, "B");
					ProgressStepSecureRaise("");
				}
				else
				{
					xml_Log.SaveLiveViewConfig(list, LiveViewCfg_RecInterval_ms, null, LiveViewCfg_ExpertEnable, "A");
					ProgressStepSecureRaise("");
					xml_Log.SaveLiveViewConfig(list2, LiveViewCfg_RecInterval_ms, null, LiveViewCfg_ExpertEnable, "B");
					ProgressStepSecureRaise("");
				}
				xml_Log.EndLog();
				SecurityEncryptToFile((string)logpath, originalStream);
				ProgressStepSecureRaise("");
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				ProgressCloseSecureRaise();
			}
			catch (NullReferenceException)
			{
				xml_Log.Close();
				ProgressCloseSecureRaise();
				MessageBox.Show("An error ocurred, engine-log-file might be corrupt\r\n\r\nInternal: signal description could not be found.", ConfigData.WizardSwName);
				if (this.ev_SessionLogTriggerSave != null)
				{
					this.ev_SessionLogTriggerSave(this, null);
				}
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
			}
			catch (Exception ex2)
			{
				xml_Log.Close();
				ProgressCloseSecureRaise();
				MessageBox.Show("An error ocurred, engine-log-file might be corrupt\r\n\r\n" + ex2.Message, ConfigData.WizardSwName);
				if (this.ev_SessionLogTriggerSave != null)
				{
					this.ev_SessionLogTriggerSave(this, null);
				}
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
			}
		}

		private void TH_DataLogLoadXML(object grnr)
		{
			GaphObj gaphObj = GraphServicesList[(int)grnr];
			UIGraphWindow gr = (UIGraphWindow)gaphObj.uiGraph;
			gr.UiGraph1.MyFileName = gaphObj.logPath;
			Xml_Log xml_Log = new Xml_Log();
			try
			{
				xml_Log.ev_ProgressClose += servicelayer_ev_ProgressClose;
				xml_Log.ev_ProgressStep += servicelayer_ev_ProgressStep;
				if (this.ev_ProgressSetup != null)
				{
					this.ev_ProgressSetup(this, new ServiceLayerStringEventArg("Loading DataLog sectors from XML_Log...\nThis may take several seconds...", 621));
				}
				if (this.ev_ProgressStep != null)
				{
					this.ev_ProgressStep(this, new ServiceLayerStringEventArg("Decrypting file"));
				}
				XmlReader xmlReader;
				try
				{
					xmlReader = XmlReader.Create(SecurityDecryptFile(gaphObj.logPath, ConfigSecurity.Zauberwort, ConfigData.e_FileTypes.DAT_LOG));
				}
				catch
				{
					if (this.ev_SecurityReEvaluateRights != null)
					{
						this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
					}
					if (this.ev_ProgressClose != null)
					{
						this.ev_ProgressClose(this, new ServiceLayerBoolEventArg(false));
					}
					if (this.ev_FormClose != null)
					{
						this.ev_FormClose(this, new EventArgs());
					}
					throw new ServiceAbortExeption("Wrong file");
				}
				bool flag = true;
				bool flag2 = true;
				string empty = string.Empty;
				Xml_Log.CXmlFileLogInfo info = new Xml_Log.CXmlFileLogInfo();
				xml_Log.ReadXmlFileLogInfo(xmlReader, ref info);
				if (baseServiceA.BaseServSecurityAccessRight() == ConfigSecurity.e_USBDongleTypes.OEM)
				{
					gr.UiGraph1.toolStripButtonExportEnabled(true);
				}
				else
				{
					gr.UiGraph1.toolStripButtonExportEnabled(false);
				}
				gr.UiGraph1.fileInfo = new FileInfoHnd();
				bool flag3 = xmlReader.ReadToFollowing("STATUS");
				string text = string.Empty;
				if (flag3)
				{
					empty = xmlReader.NamespaceURI;
					if (empty == "A")
					{
						try
						{
							RecManStatus recManStatus = xml_Log.ReadRecManStatus(xmlReader, "A");
							if (recManStatus.ActiveDatLog != 0 || recManStatus.ActiveEvRec != 0 || recManStatus.EvRecEntryCnt != 0)
							{
								xmlReader.ReadToFollowing("SECTORS", "A");
								XmlReader root = xmlReader.ReadSubtree();
								List<RecManBase.RecManSector> sectors = xml_Log.ReadRecManHexDump(root, "A");
								RecManDataLogger recManDataLogger = new RecManDataLogger(baseServiceA, ref gr);
								recManDataLogger.ViewFromHexDump(ref sectors, recManStatus, info.fileCreation);
								info.AddWarnToSectorInfo(recManDataLogger.warnToSectorInfo);
								info.AddWarnToLiLoInfo(recManDataLogger.warnToLiloInfo);
								text += recManDataLogger.testPowLev(ref info);
								gaphObj.recManA = recManDataLogger;
								gr.UiGraph1.leadInOutListA = recManDataLogger.sLeadInLeadOut.listLeadInOutInfo;
								flag = false;
							}
							xmlReader.ReadToFollowing("STATUS");
							empty = xmlReader.NamespaceURI;
						}
						catch
						{
							flag = true;
						}
					}
					if (empty == "B")
					{
						try
						{
							RecManStatus recManStatus2 = xml_Log.ReadRecManStatus(xmlReader, "B");
							if (recManStatus2.ActiveDatLog != 0 || recManStatus2.ActiveEvRec != 0 || recManStatus2.EvRecEntryCnt != 0)
							{
								xmlReader.ReadToFollowing("SECTORS", "B");
								XmlReader root2 = xmlReader.ReadSubtree();
								List<RecManBase.RecManSector> sectors2 = xml_Log.ReadRecManHexDump(root2, "B");
								RecManDataLogger recManDataLogger = new RecManDataLogger(baseServiceB, ref gr);
								recManDataLogger.ViewFromHexDump(ref sectors2, recManStatus2, info.fileCreation);
								info.AddWarnToSectorInfo(recManDataLogger.warnToSectorInfo);
								info.AddWarnToLiLoInfo(recManDataLogger.warnToLiloInfo);
								text += recManDataLogger.testPowLev(ref info);
								gaphObj.recManB = recManDataLogger;
								gr.UiGraph1.leadInOutListB = recManDataLogger.sLeadInLeadOut.listLeadInOutInfo;
								flag2 = false;
							}
						}
						catch
						{
							flag2 = true;
						}
					}
				}
				if (!flag || !flag2)
				{
					gr.UiGraph1.SizeChanged += gr.UiGraph1.ResizeUiGraph1;
					gr.UiGraph1.Addvar();
					gr.UiGraph1.UpdateData(gaphObj.recManA, null);
				}
				if (text != string.Empty)
				{
					info.AddPowerLevelWarning(text);
				}
				gr.UiGraph1.fileInfo.SetFileInfoStrm(ref info, gr.Location);
				gaphObj.uiGraph = gr;
				GraphServicesList[(int)grnr] = gaphObj;
				if (flag && flag2)
				{
					throw new Exception("Error: no sectors to decode!");
				}
				xml_Log.Close();
				if (this.ev_ProgressClose != null)
				{
					this.ev_ProgressClose(this, new ServiceLayerBoolEventArg(false));
				}
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
			}
			catch (ServiceAbortExeption)
			{
			}
			catch (Exception ex)
			{
				xml_Log.Close();
				if (this.ev_ProgressClose != null)
				{
					this.ev_ProgressClose(this, new ServiceLayerBoolEventArg(false));
				}
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				string text2 = string.Format("Error during XML import:\r\r\nFile contains no valid record manager sectors or is corrupt. {0}", ex.Message);
				MessageBox.Show(text2, ConfigData.WizardSwName);
			}
		}

		private void TH_HexDumpToXML(object datax)
		{
			RecManBase.CInDumpData cInDumpData = (RecManBase.CInDumpData)datax;
			string root = string.Empty;
			switch (cInDumpData.thProcType)
			{
			case ConfigData.EHexDumpProc.eHexDumpProc:
				root = "RECMAN_HEXDUMP";
				break;
			case ConfigData.EHexDumpProc.eReadDatLogHours:
			case ConfigData.EHexDumpProc.eReadDatLogAll:
				root = "RECMAN_HEXDUMP_DATLOG";
				break;
			case ConfigData.EHexDumpProc.eReadEventsAll:
				root = "RECMAN_HEXDUMP_EVREC";
				break;
			}
			DataLog = new Xml_Log();
			originalStream = new MemoryStream(bufUnModified, 0, bufUnModified.Length, true, true);
			originalStream.SetLength(0L);
			DataLog.CreateLogStream(originalStream, root, false);
			DataLog.FileID(Path.GetFileName(cInDumpData.logPath));
			DataLog.SwID(ConfigData.WizardSwName, ConfigData.WizardSwVersion, ConfigData.WizardManufacturer, ConfigData.EcuVersionsStrings[(uint)ConfigData.ecuSwVersion]);
			DataLog.UserID();
			TH_EngineIDSave(DataLog);
			ConfigData.ECUCONNECTED eCUCONNECTED = ECU_VerifyECUConnected();
			if (eCUCONNECTED == ConfigData.ECUCONNECTED.e_ECU_NOT_CONNECTED)
			{
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				return;
			}
			if (logECUA)
			{
				if (eCUCONNECTED == ConfigData.ECUCONNECTED.e_ECU_ALL_CONNECTED || eCUCONNECTED == ConfigData.ECUCONNECTED.e_ECU_A_CONNECTED)
				{
					datlogA.RecManInData.setCInDumpData(cInDumpData);
					datlogA.RecManInData.ecu = ConfigData.e_ECUID.A;
					datlogA.HexDumpStart();
				}
				else if (this.ev_AddConsoleEvent != null)
				{
					this.ev_AddConsoleEvent("Is not connected !!!", Color.Black, "ECU A:  ");
				}
			}
			if (logECUB)
			{
				if (eCUCONNECTED == ConfigData.ECUCONNECTED.e_ECU_ALL_CONNECTED || eCUCONNECTED == ConfigData.ECUCONNECTED.e_ECU_B_CONNECTED)
				{
					datlogB.RecManInData.setCInDumpData(cInDumpData);
					datlogB.RecManInData.ecu = ConfigData.e_ECUID.B;
					datlogB.HexDumpStart();
				}
				else if (this.ev_AddConsoleEvent != null)
				{
					this.ev_AddConsoleEvent("Is not connected !!!", Color.Black, "ECU A:  ");
				}
			}
			Thread.Sleep(15000);
			if (logECUA)
			{
				if (datlogA.RecManInData.myThread != null)
				{
					datlogA.RecManInData.myThread.Join();
				}
				if (datlogA.RecManInData.recManStatus != null && datlogA.sectorsRaw_AL != null)
				{
					DataLog.SaveRecManStatus(datlogA.RecManInData.recManStatus, "A");
					DataLog.SaveRecManSectors(ref datlogA.sectorsRaw_AL, "A");
					if (this.ev_AddConsoleEvent != null)
					{
						this.ev_AddConsoleEvent("Write RecManSectors to XML_Log Finished!", Color.Black, "ECU A:  ");
					}
					baseServiceA.CommunicationStop();
				}
			}
			if (logECUB)
			{
				if (datlogB.RecManInData.myThread != null)
				{
					datlogB.RecManInData.myThread.Join();
				}
				if (datlogB.RecManInData.recManStatus != null && datlogB.sectorsRaw_AL != null)
				{
					DataLog.SaveRecManStatus(datlogB.RecManInData.recManStatus, "B");
					DataLog.SaveRecManSectors(ref datlogB.sectorsRaw_AL, "B");
					if (this.ev_AddConsoleEvent != null)
					{
						this.ev_AddConsoleEvent("Write RecManSectors to XML_Log Finished!", Color.Black, "ECU B:  ");
					}
					baseServiceB.CommunicationStop();
				}
			}
			DataLog.EndLog();
			SecurityEncryptToFile(cInDumpData.logPath, originalStream);
			if (this.ev_ProgressClose != null)
			{
				this.ev_ProgressClose(this, new ServiceLayerBoolEventArg(false));
			}
			TH_ECUConnect(new object());
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
			Console.WriteLine("SecurityEncryptToFile( dat.logPath, originalStream ); Finished !!!");
		}

		private void TH_RecManFormat(object state)
		{
			if (ECU_VerifyBothConnected())
			{
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				if (this.ev_ProgressTimerInfoText != null)
				{
					this.ev_ProgressTimerInfoText(null, new ServiceLayerStringEventArg("Formatting RecMng-Flash ECU A...\nThis takes about 3 minutes for both ECU's."));
				}
				baseServiceA.RecManFormat1();
				if (this.ev_ProgressTimerInfoText != null)
				{
					this.ev_ProgressTimerInfoText(this, new ServiceLayerStringEventArg("Formatting RecMng-Flash ECU B...\nThis takes about 3 minutes for both ECU's."));
				}
				baseServiceB.RecManFormat1();
				if (this.ev_ProgressClose != null)
				{
					this.ev_ProgressClose(this, new ServiceLayerBoolEventArg(false));
				}
				TH_ECUDisconnect(new object());
			}
			if (this.ev_ProgressClose != null)
			{
				this.ev_ProgressClose(this, new ServiceLayerBoolEventArg(false));
			}
			if (this.ev_SessionLogTriggerSave != null)
			{
				this.ev_SessionLogTriggerSave(this, null);
			}
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
			if (this.ev_ProgressClose != null)
			{
				this.ev_ProgressClose(this, new ServiceLayerBoolEventArg(false));
			}
		}

		private void TH_EEPROM_Backup_LoadXML(object logpath)
		{
			int num = ((string)logpath).LastIndexOf('\\');
			((string)logpath).Substring(num + 1);
			XmlReader xmlReader = XmlReader.Create((string)logpath);
			Xml_LogRecMan xml_LogRecMan = new Xml_LogRecMan();
			xmlReader.ReadToFollowing("ENGINE_LOG");
			baseServiceA.EcuData.DatlogCfg = xml_LogRecMan.DatLogCfw_Load(xmlReader.ReadSubtree(), "A");
			baseServiceB.EcuData.DatlogCfg = xml_LogRecMan.DatLogCfw_Load(xmlReader.ReadSubtree(), "B");
			xmlReader.Close();
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
		}

		public void TH_EEPROM_Backup_SaveXML(object str)
		{
			Xml_LogRecMan xml_LogRecMan = new Xml_LogRecMan();
			MemoryStream fstream = new MemoryStream();
			try
			{
				TH_DatLog_Config_Read(new object());
				xml_LogRecMan.CreateLogStream(fstream, "FLASH_BACKUP", false);
				ProgressStepSecureRaise("Creating file-header...");
				xml_LogRecMan.SwID(ConfigData.WizardSwName, ConfigData.WizardSwVersion, ConfigData.WizardManufacturer, ConfigData.EcuVersionsStrings[(uint)ConfigData.ecuSwVersion]);
				ProgressStepSecureRaise("");
				xml_LogRecMan.UserID();
				ProgressStepSecureRaise("Reading engine-info...");
				TH_EngLogSave_PayloadOnly(xml_LogRecMan);
				xml_LogRecMan.DatLogCfg_Save(xml_LogRecMan.Writer, baseServiceA.EcuData.DatlogCfg, "A");
				xml_LogRecMan.DatLogCfg_Save(xml_LogRecMan.Writer, baseServiceB.EcuData.DatlogCfg, "B");
				TH_IQACylRead(ConfigData.GetIQACylCode(ConfigData.e_IQACylinder.ALL));
				xml_LogRecMan.IQACode(IQA_CylA_ReadText, IQA_CylB_ReadText);
				xml_LogRecMan.EndLog();
				if (flashLayer != null)
				{
					flashLayer.Eeprom_backup_complete = true;
				}
			}
			catch (Exception)
			{
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				return;
			}
			if (this.ev_ProgressClose != null)
			{
				this.ev_ProgressClose(this, new ServiceLayerBoolEventArg(false));
			}
			if (this.ev_SessionLogTriggerSave != null)
			{
				this.ev_SessionLogTriggerSave(this, null);
			}
			if (this.ev_SecurityReEvaluateRights != null)
			{
				this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
			}
		}

		private void TH_EvRecLoadXML(object grnr)
		{
			try
			{
				GaphObj gaphObj = GraphServicesList[(int)grnr];
				UIEvents uIEvents = (UIEvents)gaphObj.uiGraph;
				Xml_Log xml_Log = new Xml_Log();
				xml_Log.ev_ProgressClose += servicelayer_ev_ProgressClose;
				xml_Log.ev_ProgressStep += servicelayer_ev_ProgressStep;
				XmlReader xmlReader;
				try
				{
					xmlReader = XmlReader.Create(SecurityDecryptFile(gaphObj.logPath, ConfigSecurity.Zauberwort, ConfigData.e_FileTypes.EVENT_REC));
				}
				catch
				{
					if (this.ev_SecurityReEvaluateRights != null)
					{
						this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
					}
					if (this.ev_ProgressClose != null)
					{
						this.ev_ProgressClose(this, new ServiceLayerBoolEventArg(false));
					}
					if (this.ev_FormClose != null)
					{
						this.ev_FormClose(this, new EventArgs());
					}
					throw new ServiceAbortExeption("Wrong File");
				}
				if (this.ev_ProgressSetup != null)
				{
					this.ev_ProgressSetup(this, new ServiceLayerStringEventArg("Loading EvRec sectors from XML_Log...\nThis may take several seconds...", 620));
				}
				Xml_Log.CXmlFileLogInfo info = new Xml_Log.CXmlFileLogInfo();
				xml_Log.ReadXmlFileLogInfo(xmlReader, ref info);
				uIEvents.addInfoSrm(info);
				xmlReader.ReadToFollowing("STATUS");
				if (xmlReader.NamespaceURI == "A")
				{
					RecManEventRec recManEventRec = new RecManEventRec(baseServiceA);
					RecManStatus status = xml_Log.ReadRecManStatus(xmlReader, "A");
					xmlReader.ReadToFollowing("SECTORS", "A");
					XmlReader root = xmlReader.ReadSubtree();
					List<RecManBase.RecManSector> sectors = xml_Log.ReadRecManHexDump(root, "A");
					recManEventRec.ViewFromHexDump(ref sectors, status, info.fileCreation);
					uIEvents.AddEventRows(recManEventRec.eventlogger_AL, ConfigData.e_ECUS.ECU_A);
					gaphObj.recManA = recManEventRec;
					xmlReader.ReadToFollowing("STATUS");
					info.AddEvRecWarnInfo(recManEventRec.recManEventNote);
				}
				if (xmlReader.NamespaceURI == "B")
				{
					RecManEventRec recManEventRec = new RecManEventRec(baseServiceB);
					RecManStatus status2 = xml_Log.ReadRecManStatus(xmlReader, "B");
					xmlReader.ReadToFollowing("SECTORS", "B");
					XmlReader root2 = xmlReader.ReadSubtree();
					List<RecManBase.RecManSector> sectors2 = xml_Log.ReadRecManHexDump(root2, "B");
					recManEventRec.ViewFromHexDump(ref sectors2, status2, info.fileCreation);
					uIEvents.AddEventRows(recManEventRec.eventlogger_AL, ConfigData.e_ECUS.ECU_B);
					gaphObj.recManB = recManEventRec;
					info.AddEvRecWarnInfo(recManEventRec.recManEventNote);
				}
				gaphObj.uiGraph = uIEvents;
				grArr[(int)grnr] = uIEvents;
				if (this.ev_ProgressClose != null)
				{
					this.ev_ProgressClose(this, new ServiceLayerBoolEventArg(false));
				}
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				GraphServicesList[(int)grnr] = gaphObj;
			}
			catch (ServiceAbortExeption)
			{
			}
			catch (ThreadAbortException)
			{
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				if (this.ev_ProgressClose != null)
				{
					this.ev_ProgressClose(this, new ServiceLayerBoolEventArg(false));
				}
			}
			catch (Exception)
			{
				if (this.ev_SecurityReEvaluateRights != null)
				{
					this.ev_SecurityReEvaluateRights(this, new ServiceLayerBoolEventArg(false));
				}
				if (this.ev_ProgressClose != null)
				{
					this.ev_ProgressClose(this, new ServiceLayerBoolEventArg(false));
				}
				MessageBox.Show("Error during XML import:\r\r\nFile contains no valid record manager sectors or is corrupt.", ConfigData.WizardSwName);
			}
		}

		private void servicelayer_ev_ProgressStep(object sender, ServiceLayerStringEventArg e)
		{
			if (this.ev_ProgressStep != null)
			{
				this.ev_ProgressStep(sender, e);
			}
		}

		private void servicelayer_ev_ProgressClose(object sender, ServiceLayerBoolEventArg e)
		{
			if (this.ev_ProgressClose != null)
			{
				this.ev_ProgressClose(sender, e);
			}
		}

		private void servicelayer_ev_AddConsole(string s, Color c, string AB)
		{
			if (this.ev_AddConsoleEvent != null)
			{
				this.ev_AddConsoleEvent(s, c, AB);
			}
		}
	}
}
